Search in sources :

Example 1 with MavenKey

use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.

the class MavenModelReader method doRead.

private ModelReadingResult doRead(File pom) {
    List<MavenProjectProblem> problems = new ArrayList<>();
    Set<String> enabledProfiles = new HashSet<>();
    MavenModel result = new MavenModel();
    fillModelByDefaults(result);
    Model model = null;
    try {
        model = Model.readFrom(pom);
    } catch (IOException e) {
        problems.add(MavenProjectProblem.newProblem(pom.getPath(), e.getMessage(), MavenProblemType.SYNTAX));
    }
    if (model == null) {
        return new ModelReadingResult(result, problems, enabledProfiles);
    }
    final MavenKey parentKey;
    if (model.getParent() == null) {
        parentKey = result.getParent().getMavenKey();
    } else {
        Parent modelParent = model.getParent();
        parentKey = new MavenKey(modelParent.getGroupId(), modelParent.getArtifactId(), modelParent.getVersion());
        MavenParent parent = new MavenParent(parentKey, modelParent.getRelativePath());
        result.setParent(parent);
    }
    final MavenKey mavenKey = new MavenKey(getNotNull(model.getGroupId(), parentKey.getGroupId()), model.getArtifactId(), getNotNull(model.getVersion(), parentKey.getVersion()));
    result.setMavenKey(mavenKey);
    if (model.getPackaging() != null) {
        result.setPackaging(model.getPackaging());
    }
    result.setName(model.getName());
    final List<String> modules = model.getModules();
    if (modules != null) {
        result.setModules(new ArrayList<>(model.getModules()));
    }
    Map<String, String> properties = model.getProperties();
    Properties prop = new Properties();
    if (properties != null) {
        prop.putAll(properties);
    }
    result.setProperties(prop);
    final Build build = model.getBuild();
    if (build != null) {
        final String sourceDirectory = build.getSourceDirectory();
        if (sourceDirectory != null) {
            result.getBuild().setSources(singletonList(sourceDirectory));
        }
        final String testSourceDirectory = build.getTestSourceDirectory();
        if (testSourceDirectory != null) {
            result.getBuild().setTestSources(singletonList(testSourceDirectory));
        }
        result.getBuild().setResources(convertResources(build.getResources()));
    }
    //TODO add profiles
    return new ModelReadingResult(result, problems, enabledProfiles);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) MavenParent(org.eclipse.che.maven.data.MavenParent) Parent(org.eclipse.che.ide.maven.tools.Parent) ArrayList(java.util.ArrayList) MavenParent(org.eclipse.che.maven.data.MavenParent) IOException(java.io.IOException) Properties(java.util.Properties) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenBuild(org.eclipse.che.maven.data.MavenBuild) Build(org.eclipse.che.ide.maven.tools.Build) Model(org.eclipse.che.ide.maven.tools.Model) MavenModel(org.eclipse.che.maven.data.MavenModel) HashSet(java.util.HashSet)

Example 2 with MavenKey

use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.

the class MavenProjectManager method clearMavenKeyMap.

private void clearMavenKeyMap(MavenProject mavenProject) {
    MavenKey mavenKey = mavenProject.getMavenKey();
    mavenWorkspaceCache.invalidate(mavenKey);
    keyToProjectMap.remove(mavenKey);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey)

Example 3 with MavenKey

use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.

the class MavenProjectManager method findDependentProjects.

public List<MavenProject> findDependentProjects(List<MavenProject> projects) {
    readLock.lock();
    try {
        List<MavenProject> result = new ArrayList<>();
        Set<MavenKey> mavenKeys = projects.stream().map(MavenProject::getMavenKey).collect(Collectors.toSet());
        Set<String> paths = projects.stream().map(project -> project.getProject().getFullPath().toOSString()).collect(Collectors.toSet());
        for (MavenProject project : projectToMavenProjectMap.values()) {
            boolean isAdd = false;
            for (String path : project.getModulesPath()) {
                if (paths.contains(path)) {
                    isAdd = true;
                    break;
                }
            }
            if (!isAdd) {
                for (MavenArtifact artifact : project.getDependencies()) {
                    if (contains(mavenKeys, artifact.getArtifactId(), artifact.getGroupId(), artifact.getVersion())) {
                        isAdd = true;
                        break;
                    }
                }
            }
            if (isAdd) {
                result.add(project);
            }
        }
        return result;
    } finally {
        readLock.unlock();
    }
}
Also used : MavenServerManager(org.eclipse.che.plugin.maven.server.MavenServerManager) MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) Proxy(java.lang.reflect.Proxy) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Deque(java.util.Deque) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Map(java.util.Map) LinkedList(java.util.LinkedList) Set(java.util.Set) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MavenProjectModifications(org.eclipse.che.plugin.maven.server.core.project.MavenProjectModifications) Provider(com.google.inject.Provider) MavenKey(org.eclipse.che.maven.data.MavenKey) List(java.util.List) Lock(java.util.concurrent.locks.Lock) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenWorkspaceCache(org.eclipse.che.maven.data.MavenWorkspaceCache) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MavenKey(org.eclipse.che.maven.data.MavenKey) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact)

Example 4 with MavenKey

use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.

the class MavenProjectManager method fillMavenKeyMap.

private void fillMavenKeyMap(MavenProject mavenProject) {
    MavenKey mavenKey = mavenProject.getMavenKey();
    mavenWorkspaceCache.put(mavenKey, mavenProject.getPomFile());
    keyToProjectMap.put(mavenKey, mavenProject);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey)

Example 5 with MavenKey

use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.

the class MavenProject method setModel.

private MavenProjectModifications setModel(MavenModelReaderResult readerResult, boolean clearArtifacts, boolean clearProfiles) {
    Info newInfo = info.clone();
    newInfo.problems = readerResult.getProblems();
    newInfo.activeProfiles = readerResult.getActiveProfiles();
    MavenModel model = readerResult.getMavenModel();
    newInfo.mavenKey = model.getMavenKey();
    if (model.getParent() != null) {
        newInfo.parentKey = model.getParent().getMavenKey();
    }
    newInfo.packaging = model.getPackaging();
    newInfo.name = model.getName();
    newInfo.sources = model.getBuild().getSources();
    newInfo.testSources = model.getBuild().getTestSources();
    newInfo.resources = model.getBuild().getResources();
    newInfo.testResources = model.getBuild().getTestResources();
    newInfo.properties = model.getProperties();
    newInfo.filters = model.getBuild().getFilters();
    Set<MavenRemoteRepository> remoteRepositories = new HashSet<>();
    Set<MavenArtifact> extensions = new HashSet<>();
    Set<MavenArtifact> dependencies = new HashSet<>();
    Set<MavenPlugin> plugins = new HashSet<>();
    Set<MavenKey> unresolvedArtifacts = new HashSet<>();
    if (!clearArtifacts) {
        if (info.remoteRepositories != null) {
            remoteRepositories.addAll(info.remoteRepositories);
        }
        if (info.extensions != null) {
            extensions.addAll(info.extensions);
        }
        if (info.dependencies != null) {
            dependencies.addAll(info.dependencies);
        }
        if (info.plugins != null) {
            plugins.addAll(info.plugins);
        }
        if (info.unresolvedArtifacts != null) {
            unresolvedArtifacts.addAll(info.unresolvedArtifacts);
        }
    }
    remoteRepositories.addAll(model.getRemoteRepositories());
    extensions.addAll(model.getExtensions());
    dependencies.addAll(model.getDependencies());
    plugins.addAll(model.getPlugins());
    unresolvedArtifacts.addAll(readerResult.getUnresolvedArtifacts());
    newInfo.remoteRepositories = new ArrayList<>(remoteRepositories);
    newInfo.extensions = new ArrayList<>(extensions);
    newInfo.dependencies = new ArrayList<>(dependencies);
    newInfo.plugins = new ArrayList<>(plugins);
    newInfo.unresolvedArtifacts = unresolvedArtifacts;
    newInfo.modulesNameToPath = collectModulesNameAndPath(model);
    return setInfo(newInfo);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) MavenModel(org.eclipse.che.maven.data.MavenModel) MavenPlugin(org.eclipse.che.maven.data.MavenPlugin) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) HashSet(java.util.HashSet)

Aggregations

MavenKey (org.eclipse.che.maven.data.MavenKey)17 MavenModel (org.eclipse.che.maven.data.MavenModel)6 MavenProject (org.eclipse.che.plugin.maven.server.core.project.MavenProject)6 Test (org.testng.annotations.Test)6 HashSet (java.util.HashSet)4 MavenParent (org.eclipse.che.maven.data.MavenParent)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)3 MavenBuild (org.eclipse.che.maven.data.MavenBuild)3 MavenWorkspaceCache (org.eclipse.che.maven.data.MavenWorkspaceCache)3 IProject (org.eclipse.core.resources.IProject)3 Path (org.eclipse.core.runtime.Path)3 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 Parent (org.apache.maven.model.Parent)2 MavenProjectProblem (org.eclipse.che.maven.data.MavenProjectProblem)2 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 Singleton (com.google.inject.Singleton)1