use of meghanada.project.ProjectDependency in project meghanada-server by mopemope.
the class AndroidSupport method parseAndroidProject.
void parseAndroidProject(AndroidProject androidProject) throws IOException {
JavaCompileOptions javaCompileOptions = androidProject.getJavaCompileOptions();
this.project.setCompileSource(javaCompileOptions.getSourceCompatibility());
this.project.setCompileTarget(javaCompileOptions.getTargetCompatibility());
ProductFlavorContainer defaultConfig = androidProject.getDefaultConfig();
if (isNull(this.project.getOutput())) {
File buildDir = androidProject.getBuildFolder().getCanonicalFile();
String build = Joiner.on(File.separator).join(buildDir, INTERMEDIATE_DIR, CLASSES_DIR, DEBUG_DIR);
this.project.setOutput(project.normalize(build));
}
if (isNull(this.project.getTestOutput())) {
File buildDir = androidProject.getBuildFolder().getCanonicalFile();
String build = Joiner.on(File.separator).join(buildDir, INTERMEDIATE_DIR, CLASSES_DIR, TEST_DIR, DEBUG_DIR);
this.project.setTestOutput(this.project.normalize(build));
}
Map<String, Set<File>> androidSources = this.getAndroidSources(defaultConfig);
Set<ProjectDependency> dependencies = this.getAndroidDependencies(androidProject);
this.project.getSources().addAll(androidSources.getOrDefault(SOURCES_KEY, new HashSet<>()));
this.project.getResources().addAll(androidSources.getOrDefault(RESOURCES_KEY, new HashSet<>()));
this.project.getTestSources().addAll(androidSources.getOrDefault(TEST_SOURCES_KEY, new HashSet<>()));
this.project.getTestResources().addAll(androidSources.getOrDefault(AndroidSupport.TEST_RESOURCES_KEY, new HashSet<>()));
this.project.getDependencies().addAll(dependencies);
// merge other project
if (this.project.getSources().isEmpty()) {
File file = new File(Joiner.on(File.separator).join(SRC_DIR, MAIN_DIR, JAVA_DIR)).getCanonicalFile();
this.project.getSources().add(file);
}
if (this.project.getTestSources().isEmpty()) {
File file = new File(Joiner.on(File.separator).join(SRC_DIR, TEST_DIR, JAVA_DIR)).getCanonicalFile();
this.project.getTestSources().add(file);
}
if (isNull(this.project.getOutput())) {
String buildDir = new File(this.project.getProjectRoot(), BUILD_DIR).getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, INTERMEDIATE_DIR, CLASSES_DIR, DEBUG_DIR);
this.project.setOutput(this.project.normalize(build));
}
if (isNull(this.project.getTestOutput())) {
String buildDir = new File(this.project.getProjectRoot(), BUILD_DIR).getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, INTERMEDIATE_DIR, CLASSES_DIR, TEST_DIR, DEBUG_DIR);
this.project.setTestOutput(this.project.normalize(build));
}
// load exists aar
String aar = Joiner.on(File.separator).join(this.project.getProjectRoot(), BUILD_DIR, INTERMEDIATE_DIR, EXPLODED_DIR);
FileUtils.collectFiles(new File(aar), EXT_JAR).forEach(wrapIOConsumer(this::addAAR));
log.debug("sources {}", this.project.getSources());
log.debug("resources {}", this.project.getResources());
log.debug("output {}", this.project.getOutput());
log.debug("test sources {}", this.project.getTestSources());
log.debug("test resources {}", this.project.getTestResources());
log.debug("test output {}", this.project.getTestOutput());
for (ProjectDependency projectDependency : this.project.getDependencies()) {
log.debug("dependency {}", projectDependency);
}
}
use of meghanada.project.ProjectDependency in project meghanada-server by mopemope.
the class AndroidSupport method getAndroidDependencies.
private Set<ProjectDependency> getAndroidDependencies(AndroidProject androidProject) {
Set<ProjectDependency> dependencies = new HashSet<>(16);
Collection<String> bootClasspath = androidProject.getBootClasspath();
for (String cp : bootClasspath) {
File file = new File(cp);
addDependencies(dependencies, file);
}
Collection<Variant> variants = androidProject.getVariants();
for (Variant variant : variants) {
String buildType = variant.getBuildType();
boolean debugBuild = buildType.equals(DEBUG_BUILD);
AndroidArtifact mainArtifact = variant.getMainArtifact();
if (debugBuild) {
Collection<File> generatedSourceFolders = mainArtifact.getGeneratedSourceFolders();
for (File src : generatedSourceFolders) {
this.project.getSources().add(src);
}
Collection<File> generatedResourceFolders = mainArtifact.getGeneratedResourceFolders();
for (File src : generatedResourceFolders) {
this.project.getResources().add(src);
}
}
Dependencies compileDependencies = mainArtifact.getDependencies();
Collection<AndroidLibrary> libraries = compileDependencies.getLibraries();
for (AndroidLibrary androidLibrary : libraries) {
String project = androidLibrary.getProject();
if (nonNull(project) && !androidLibrary.isProvided()) {
if (project.startsWith(":")) {
project = project.substring(1);
}
if (this.project.allModules.containsKey(project)) {
File root = this.project.allModules.get(project);
final ProjectDependency projectDependency = new ProjectDependency(project, "COMPILE", "1.0.0", root, ProjectDependency.Type.PROJECT);
dependencies.add(projectDependency);
}
}
Collection<File> localJars = androidLibrary.getLocalJars();
for (File jar : localJars) {
addDependencies(dependencies, jar);
}
}
Collection<JavaLibrary> javaLibraries = compileDependencies.getJavaLibraries();
for (JavaLibrary javaLibrary : javaLibraries) {
File file = javaLibrary.getJarFile();
addDependencies(dependencies, file);
}
parseExtraAndroidArtifacts(dependencies, variant);
parseExtraJavaArtifacts(dependencies, variant);
}
return dependencies;
}
use of meghanada.project.ProjectDependency in project meghanada-server by mopemope.
the class GradleProject method parseIdeaModule.
private void parseIdeaModule(final IdeaModule ideaModule) throws IOException {
final org.gradle.tooling.model.GradleProject gradleProject = ideaModule.getGradleProject();
String name = convertName(gradleProject.getPath());
if (nonNull(name) && !name.isEmpty()) {
this.name = name;
}
final AndroidProject androidProject = AndroidSupport.getAndroidProject(this.rootProject, gradleProject);
if (nonNull(androidProject)) {
Set<ProjectDependency> projectDependencies = analyzeDependencies(ideaModule);
this.dependencies.addAll(projectDependencies);
// parse android
this.isAndroidProject = true;
this.androidApiVersion = androidProject.getApiVersion();
this.androidModelVersion = androidProject.getModelVersion();
final AndroidSupport androidSupport = new AndroidSupport(this);
androidSupport.parseAndroidProject(androidProject);
} else {
// normal
this.parseIdeaModule(gradleProject, ideaModule);
}
}
use of meghanada.project.ProjectDependency in project meghanada-server by mopemope.
the class GradleProject method parseIdeaModule.
private void parseIdeaModule(final org.gradle.tooling.model.GradleProject gradleProject, final IdeaModule ideaModule) throws IOException {
if (isNull(this.output)) {
final String buildDir = gradleProject.getBuildDirectory().getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, "classes", "main");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(buildDir, "classes", "java", "main");
}
this.output = this.normalize(build);
}
if (isNull(this.testOutput)) {
final String buildDir = gradleProject.getBuildDirectory().getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, "classes", "test");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(buildDir, "classes", "java", "test");
}
this.testOutput = this.normalize(build);
}
final Set<ProjectDependency> dependencies = this.analyzeDependencies(ideaModule);
final Map<String, Set<File>> sources = this.searchProjectSources(ideaModule);
this.sources.addAll(sources.get("sources"));
this.resources.addAll(sources.get("resources"));
this.testSources.addAll(sources.get("testSources"));
this.testResources.addAll(sources.get("testResources"));
this.dependencies.addAll(dependencies);
// merge other project
if (this.sources.isEmpty()) {
final File file = new File(Joiner.on(File.separator).join("src", "main", "java")).getCanonicalFile();
this.sources.add(file);
}
if (this.testSources.isEmpty()) {
final File file = new File(Joiner.on(File.separator).join("src", "test", "java")).getCanonicalFile();
this.testSources.add(file);
}
if (isNull(this.output)) {
final String buildDir = new File(this.getProjectRoot(), "build").getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, "classes", "main");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(buildDir, "classes", "java", "main");
}
this.output = this.normalize(build);
}
if (isNull(this.testOutput)) {
final String buildDir = new File(this.getProjectRoot(), "build").getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, "classes", "test");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(buildDir, "classes", "java", "test");
}
this.testOutput = this.normalize(build);
}
log.debug("sources {}", this.sources);
log.debug("resources {}", this.resources);
log.debug("output {}", this.output);
log.debug("test sources {}", this.testSources);
log.debug("test resources {}", this.testResources);
log.debug("test output {}", this.testOutput);
for (final ProjectDependency projectDependency : this.getDependencies()) {
log.debug("{} {}", projectDependency.getScope(), projectDependency.getId());
}
}
use of meghanada.project.ProjectDependency in project meghanada-server by mopemope.
the class LocationSearcher method searchFromDependency.
private Location searchFromDependency(final SearchContext context) throws IOException {
final String searchFQCN = context.searchFQCN;
final CachedASMReflector reflector = CachedASMReflector.getInstance();
final File classFile = reflector.getClassFile(searchFQCN);
final String tempDir = System.getProperty("java.io.tmpdir");
if (classFile != null && classFile.exists() && classFile.getName().endsWith(FileUtils.JAR_EXT)) {
final String androidHome = System.getenv("ANDROID_HOME");
if (androidHome != null) {
final Optional<ProjectDependency> dependencyOptional = this.project.getDependencies().stream().filter(dependency -> dependency.getFile().equals(classFile)).findFirst();
if (dependencyOptional.isPresent()) {
final ProjectDependency dependency = dependencyOptional.get();
final String sourceJar = ClassNameUtils.getSimpleName(dependency.getId()) + '-' + dependency.getVersion() + "-sources.jar";
final File root = new File(androidHome, "extras");
if (root.exists()) {
return getLocationFromSrcOrDecompile(context, classFile, root, sourceJar);
}
}
}
final File depParent = classFile.getParentFile();
final File dependencyDir = depParent.getParentFile();
final String srcJarName = ClassNameUtils.replace(classFile.getName(), FileUtils.JAR_EXT, "-sources.jar");
final String disable = System.getProperty("disable-source-jar");
if (disable != null && disable.equals("true")) {
return searchLocationFromDecompileFile(context, searchFQCN, classFile, tempDir);
}
return getLocationFromSrcOrDecompile(context, classFile, dependencyDir, srcJarName);
}
return null;
}
Aggregations