Search in sources :

Example 6 with ProjectDependency

use of meghanada.project.ProjectDependency in project meghanada-server by mopemope.

the class AndroidSupport method addAAR.

private void addAAR(File jar) {
    String pkg = jar.getParentFile().getParentFile().getParentFile().getParentFile().getName();
    String name = jar.getParentFile().getParentFile().getParentFile().getName();
    String id = pkg + '.' + name;
    String version = jar.getParentFile().getParentFile().getName();
    ProjectDependency projectDependency = new ProjectDependency(id, DEFAULT_SCOPE, version, jar, ProjectDependency.Type.JAR);
    this.project.getDependencies().add(projectDependency);
}
Also used : ProjectDependency(meghanada.project.ProjectDependency)

Example 7 with ProjectDependency

use of meghanada.project.ProjectDependency in project meghanada-server by mopemope.

the class AndroidSupport method addDependencies.

private void addDependencies(Set<ProjectDependency> dependencies, File jar) {
    String id = jar.getName();
    String version = DEFAULT_VERSION;
    String scope = DEFAULT_SCOPE;
    ProjectDependency projectDependency = new ProjectDependency(id, scope, version, jar, ProjectDependency.Type.JAR);
    dependencies.add(projectDependency);
}
Also used : ProjectDependency(meghanada.project.ProjectDependency)

Example 8 with ProjectDependency

use of meghanada.project.ProjectDependency in project meghanada-server by mopemope.

the class GradleProject method analyzeDependencies.

private Set<ProjectDependency> analyzeDependencies(final IdeaModule ideaModule) {
    final Set<ProjectDependency> dependencies = new HashSet<>(16);
    for (final IdeaDependency dependency : ideaModule.getDependencies().getAll()) {
        if (dependency instanceof IdeaSingleEntryLibraryDependency) {
            final IdeaSingleEntryLibraryDependency libraryDependency = (IdeaSingleEntryLibraryDependency) dependency;
            final File file = libraryDependency.getFile();
            final GradleModuleVersion gradleModuleVersion = libraryDependency.getGradleModuleVersion();
            String scope = libraryDependency.getScope().getScope();
            String id;
            String version;
            if (isNull(gradleModuleVersion)) {
                id = file.getName();
                // dummy
                version = "1.0.0";
            } else {
                id = String.join(":", gradleModuleVersion.getGroup(), gradleModuleVersion.getName(), gradleModuleVersion.getVersion());
                version = gradleModuleVersion.getVersion();
            }
            if (isNull(scope)) {
                scope = "COMPILE";
            }
            if (!scope.equals("PROVIDED")) {
                final ProjectDependency.Type type = ProjectDependency.getFileType(file);
                final ProjectDependency projectDependency = new ProjectDependency(id, scope, version, file, type);
                dependencies.add(projectDependency);
            }
        } else if (dependency instanceof IdeaModuleDependency) {
            final IdeaModuleDependency moduleDependency = (IdeaModuleDependency) dependency;
            final String scope = moduleDependency.getScope().getScope();
            final String moduleName = moduleDependency.getTargetModuleName();
            this.allModules.computeIfPresent(moduleName, (key, projectRoot) -> {
                final ProjectDependency projectDependency = new ProjectDependency(key, scope, "1.0.0", projectRoot, ProjectDependency.Type.PROJECT);
                dependencies.add(projectDependency);
                return projectRoot;
            });
            if (!this.allModules.containsKey(moduleName)) {
                log.warn("missing module:{}", moduleName);
            }
        } else {
            log.warn("dep ??? class={}", dependency.getClass());
        }
    }
    return dependencies;
}
Also used : Config.debugTimeItF(meghanada.config.Config.debugTimeItF) IdeaDependency(org.gradle.tooling.model.idea.IdeaDependency) ProjectParseException(meghanada.project.ProjectParseException) IdeaJavaLanguageSettings(org.gradle.tooling.model.idea.IdeaJavaLanguageSettings) FunctionUtils.wrapIOConsumer(meghanada.utils.FunctionUtils.wrapIOConsumer) StringUtils(org.apache.commons.lang3.StringUtils) PipedInputStream(java.io.PipedInputStream) Map(java.util.Map) GradleConnector(org.gradle.tooling.GradleConnector) Objects.isNull(java.util.Objects.isNull) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) Splitter(com.google.common.base.Splitter) GradleVersion(org.gradle.util.GradleVersion) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) BuildLauncher(org.gradle.tooling.BuildLauncher) CompileResult(meghanada.analyze.CompileResult) AndroidProject(com.android.builder.model.AndroidProject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) ResultHandler(org.gradle.tooling.ResultHandler) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ClassNameUtils(meghanada.utils.ClassNameUtils) IdeaContentRoot(org.gradle.tooling.model.idea.IdeaContentRoot) IdeaSingleEntryLibraryDependency(org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) Project(meghanada.project.Project) Objects.nonNull(java.util.Objects.nonNull) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) GradleConnectionException(org.gradle.tooling.GradleConnectionException) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Files(com.google.common.io.Files) ConfigFactory(com.typesafe.config.ConfigFactory) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) IdeaModuleDependency(org.gradle.tooling.model.idea.IdeaModuleDependency) DomainObjectSet(org.gradle.tooling.model.DomainObjectSet) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion) ProjectConnection(org.gradle.tooling.ProjectConnection) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) IdeaSingleEntryLibraryDependency(org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency) IdeaDependency(org.gradle.tooling.model.idea.IdeaDependency) IdeaModuleDependency(org.gradle.tooling.model.idea.IdeaModuleDependency) ProjectDependency(meghanada.project.ProjectDependency) File(java.io.File) HashSet(java.util.HashSet) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion)

Example 9 with ProjectDependency

use of meghanada.project.ProjectDependency 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;
}
Also used : ProjectParseException(meghanada.project.ProjectParseException) IOException(java.io.IOException) ProjectDependency(meghanada.project.ProjectDependency) File(java.io.File)

Aggregations

ProjectDependency (meghanada.project.ProjectDependency)9 File (java.io.File)6 HashSet (java.util.HashSet)4 IOException (java.io.IOException)3 Set (java.util.Set)3 AndroidProject (com.android.builder.model.AndroidProject)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ProjectParseException (meghanada.project.ProjectParseException)2 AndroidArtifact (com.android.builder.model.AndroidArtifact)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 Dependencies (com.android.builder.model.Dependencies)1 JavaCompileOptions (com.android.builder.model.JavaCompileOptions)1 JavaLibrary (com.android.builder.model.JavaLibrary)1 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)1 Variant (com.android.builder.model.Variant)1 JavaParser (com.github.javaparser.JavaParser)1