use of meghanada.project.ProjectParseException in project meghanada-server by mopemope.
the class GradleProject method parseProject.
@Override
public Project parseProject() throws ProjectParseException {
final ProjectConnection connection = getProjectConnection();
log.info("loading gradle project:{}", new File(this.projectRoot, Project.GRADLE_PROJECT_FILE));
try {
BuildEnvironment env = connection.getModel(BuildEnvironment.class);
String version = env.getGradle().getGradleVersion();
if (isNull(version)) {
version = GradleVersion.current().getVersion();
}
if (nonNull(version)) {
this.gradleVersion = new ComparableVersion(version);
}
final IdeaProject ideaProject = debugTimeItF("get idea project model elapsed={}", () -> connection.getModel(IdeaProject.class));
this.setCompileTarget(ideaProject);
log.trace("load root project path:{}", this.rootProject);
final DomainObjectSet<? extends IdeaModule> modules = ideaProject.getModules();
final List<? extends IdeaModule> mainModules = modules.parallelStream().filter(ideaModule -> {
final org.gradle.tooling.model.GradleProject gradleProject = ideaModule.getGradleProject();
final File moduleProjectRoot = gradleProject.getProjectDirectory();
final String name = ideaModule.getName();
log.trace("find sub-module name {} path {} ", name, moduleProjectRoot);
this.allModules.putIfAbsent(name, moduleProjectRoot);
return moduleProjectRoot.equals(this.getProjectRoot());
}).collect(Collectors.toList());
mainModules.forEach(wrapIOConsumer(this::parseIdeaModule));
// set default output
if (isNull(super.output)) {
String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "main");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "main");
}
super.output = this.normalize(build);
}
if (isNull(super.testOutput)) {
String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "test");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "test");
}
super.testOutput = this.normalize(build);
}
return this;
} catch (Exception e) {
throw new ProjectParseException(e);
} finally {
connection.close();
}
}
use of meghanada.project.ProjectParseException in project meghanada-server by mopemope.
the class POMParser method parsePom.
POMInfo parsePom(File pom) throws ProjectParseException {
try {
if (!pom.isAbsolute()) {
pom = pom.getCanonicalFile();
}
ModelBuildingRequest req = new DefaultModelBuildingRequest();
req.setPomFile(pom);
req.setSystemProperties(System.getProperties());
req.setModelResolver(new LocalModelResolver(this.projectRoot));
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
req.setProcessPlugins(true);
DefaultModelBuilderFactory factory = new DefaultModelBuilderFactory();
DefaultModelBuilder builder = factory.newInstance();
ModelBuildingResult result = builder.build(req);
Model mavenModel = result.getEffectiveModel();
POMInfo pomInfo = new POMInfo(pom.getParent());
String groupId = mavenModel.getGroupId();
if (nonNull(groupId)) {
pomInfo.groupId = groupId;
}
String artifactId = mavenModel.getArtifactId();
if (nonNull(artifactId)) {
pomInfo.artifactId = artifactId;
}
String version = mavenModel.getVersion();
if (nonNull(version)) {
pomInfo.version = version;
}
Properties modelProperties = mavenModel.getProperties();
if (nonNull(modelProperties)) {
if (nonNull(groupId)) {
modelProperties.put("project.groupId", groupId);
}
if (nonNull(artifactId)) {
modelProperties.put("project.artifactId", artifactId);
}
if (nonNull(version)) {
modelProperties.put("project.version", version);
}
for (String key : modelProperties.stringPropertyNames()) {
String value = modelProperties.getProperty(key);
if (nonNull(value)) {
pomInfo.properties.setProperty(key, value);
}
}
POMParser.replacePOMProperties(pomInfo);
}
Build build = mavenModel.getBuild();
this.parseBuild(pomInfo, build);
return pomInfo;
} catch (IOException | ModelBuildingException e) {
throw new ProjectParseException(e);
}
}
use of meghanada.project.ProjectParseException in project meghanada-server by mopemope.
the class MavenProject method parseProject.
@Override
public Project parseProject() throws ProjectParseException {
try {
final String mavenPath = Config.load().getMavenPath();
if (!Strings.isNullOrEmpty(mavenPath)) {
this.mavenCmd = mavenPath;
}
final File logFile = File.createTempFile("meghanada-maven-classpath", ".log");
logFile.deleteOnExit();
final String logPath = logFile.getCanonicalPath();
log.info("running maven. resolve dependencies ...");
if (this.runMvn(RESOLVE_TASK, SOURCES_TASK, BUILD_CLASSPATH_TASK, String.format("-Dmdep.outputFile=%s", logPath)) != 0) {
throw new ProjectParseException("Could not resolve dependencies. please try 'mvn dependency:resolve' or 'mvn install'");
}
final String cpTxt = Files.asCharSource(logFile, StandardCharsets.UTF_8).readFirstLine();
if (cpTxt != null && !cpTxt.isEmpty()) {
for (final String dep : Splitter.on(File.pathSeparator).split(cpTxt)) {
final File file = new File(dep);
final String parentPath = file.getParent();
final String version = MavenProject.getVersion(parentPath);
final String code = MavenProject.getArtifactCode(parentPath);
final ProjectDependency.Type type = ProjectDependency.getFileType(file);
final ProjectDependency dependency = new ProjectDependency(code, "COMPILE", version, file, type);
super.dependencies.add(dependency);
}
}
final POMParser pomParser = new POMParser(this.projectRoot);
final POMInfo pomInfo = pomParser.parsePom(this.pomFile);
{
super.sources.addAll(pomInfo.getSourceDirectory());
File src = new File(this.projectRoot, String.join(File.separator, "src", "main", "java"));
super.sources.add(src);
super.resources.addAll(pomInfo.getResourceDirectories());
File resource = new File(this.projectRoot, String.join(File.separator, "src", "main", "resource"));
super.resources.add(resource);
File output = pomInfo.getOutputDirectory();
if (output == null) {
output = new File(this.projectRoot, String.join(File.separator, "target", "classes"));
}
super.output = output;
}
{
super.testSources.addAll(pomInfo.getTestSourceDirectory());
File src = new File(this.projectRoot, String.join(File.separator, "src", "test", "java"));
super.testSources.add(src);
super.testResources.addAll(pomInfo.getTestResourceDirectories());
File testResource = new File(this.projectRoot, String.join(File.separator, "src", "test", "resource"));
super.testResources.add(testResource);
File output = pomInfo.getTestOutputDirectory();
if (output == null) {
output = new File(this.projectRoot, String.join(File.separator, "target", "test-classes"));
}
super.testOutput = output;
}
super.compileSource = pomInfo.compileSource;
super.compileTarget = pomInfo.compileTarget;
} catch (IOException | InterruptedException e) {
throw new ProjectParseException(e);
}
return this;
}
Aggregations