generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yannick da Silva Bröker <ybroeker@techfak.uni-bielefeld.de>
- Loading branch information
Showing
10 changed files
with
211 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/com/github/ybroeker/pmdidea/pmd/AuxClassPathFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.github.ybroeker.pmdidea.pmd; | ||
|
||
import java.io.File; | ||
import java.nio.file.*; | ||
import java.util.*; | ||
|
||
import com.intellij.openapi.components.Service; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleManager; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.roots.OrderEnumerator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
@Service | ||
public final class AuxClassPathFactory { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(AuxClassPathFactory.class); | ||
|
||
private final Project project; | ||
|
||
public AuxClassPathFactory(final Project project) { | ||
this.project = project; | ||
} | ||
|
||
|
||
public String getClassPath() { | ||
final List<Path> paths = getClassPathEntries(); | ||
|
||
return joinClassPathEntries(paths); | ||
} | ||
|
||
private List<Path> getClassPathEntries() { | ||
final Module[] modules = ModuleManager.getInstance(project).getModules(); | ||
|
||
final List<Path> paths = new ArrayList<>(); | ||
|
||
for (final Module module : modules) { | ||
final List<String> pathList = OrderEnumerator.orderEntries(module).recursively().getPathsList().getPathList(); | ||
for (final String pathString : pathList) { | ||
final Path path = Paths.get(pathString); | ||
if (Files.exists(path)) { | ||
paths.add(path); | ||
LOGGER.trace("Include in Classpath: {}", path); | ||
} else { | ||
LOGGER.trace("Exclude from Classpath: {}", path); | ||
} | ||
} | ||
} | ||
return paths; | ||
} | ||
|
||
private String joinClassPathEntries(final List<Path> paths) { | ||
final StringJoiner joiner = new StringJoiner(File.pathSeparator); | ||
for (final Path path : paths) { | ||
joiner.add(path.toAbsolutePath().toString()); | ||
} | ||
return joiner.toString(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/github/ybroeker/pmdidea/pmd/PmdConfigurationFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.ybroeker.pmdidea.pmd; | ||
|
||
import java.util.List; | ||
|
||
import com.github.ybroeker.pmdidea.config.PmdConfigurationService; | ||
import com.intellij.openapi.components.Service; | ||
import com.intellij.openapi.project.Project; | ||
|
||
|
||
@Service | ||
public final class PmdConfigurationFactory { | ||
|
||
private final Project project; | ||
|
||
public PmdConfigurationFactory(final Project project) { | ||
this.project = project; | ||
} | ||
|
||
public PmdConfiguration getPmdConfiguration(final List<ScannableFile> files, final PmdRunListener pmdRunListener) { | ||
final RulesService rulesService = project.getService(RulesService.class); | ||
final PmdConfigurationService service = project.getService(PmdConfigurationService.class); | ||
final PmdOptions pmdOptions = new PmdOptions(service.getState().getJdkVersion().toString(), service.getState().getPmdVersion()); | ||
final String classPath = project.getService(AuxClassPathFactory.class).getClassPath(); | ||
|
||
return new PmdConfiguration(project, files, rulesService.getRulesPath(), pmdOptions, pmdRunListener, classPath); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/github/ybroeker/pmdidea/pmd/RulesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.ybroeker.pmdidea.pmd; | ||
|
||
import java.nio.file.*; | ||
import java.util.Optional; | ||
|
||
import com.github.ybroeker.pmdidea.config.PmdConfigurationService; | ||
import com.intellij.openapi.components.Service; | ||
import com.intellij.openapi.project.Project; | ||
|
||
@Service | ||
public final class RulesService { | ||
|
||
private final Project project; | ||
|
||
public RulesService(final Project project) { | ||
this.project = project; | ||
} | ||
|
||
|
||
public String getRulesPath() { | ||
return getRules().orElseThrow(() -> new IllegalStateException("No valid ruleset found!")); | ||
} | ||
|
||
public boolean hasValidRuleSet() { | ||
return getRules().isPresent(); | ||
} | ||
|
||
|
||
private Optional<String> getRules() { | ||
final PmdConfigurationService service = project.getService(PmdConfigurationService.class); | ||
final String pathName = service.getState().getRulesPath(); | ||
if (pathName == null || pathName.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
final Path rulesPath = Paths.get(pathName); | ||
if (!Files.exists(rulesPath)) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(pathName); | ||
} | ||
|
||
} |
Oops, something went wrong.