Search in sources :

Example 1 with MavenResource

use of org.jetbrains.idea.maven.model.MavenResource in project intellij-community by JetBrains.

the class MavenResourceCompilerConfigurationGenerator method addNonMavenResources.

private void addNonMavenResources(MavenProjectConfiguration projectCfg) {
    Set<VirtualFile> processedRoots = new HashSet<>();
    for (MavenProject project : myMavenProjectsManager.getProjects()) {
        for (String dir : ContainerUtil.concat(project.getSources(), project.getTestSources())) {
            VirtualFile file = LocalFileSystem.getInstance().findFileByPath(dir);
            if (file != null) {
                processedRoots.add(file);
            }
        }
        for (MavenResource resource : ContainerUtil.concat(project.getResources(), project.getTestResources())) {
            VirtualFile file = LocalFileSystem.getInstance().findFileByPath(resource.getDirectory());
            if (file != null) {
                processedRoots.add(file);
            }
        }
    }
    CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(myProject);
    for (Module module : ModuleManager.getInstance(myProject).getModules()) {
        if (!myMavenProjectsManager.isMavenizedModule(module))
            continue;
        for (ContentEntry contentEntry : ModuleRootManager.getInstance(module).getContentEntries()) {
            for (SourceFolder folder : contentEntry.getSourceFolders()) {
                VirtualFile file = folder.getFile();
                if (file == null)
                    continue;
                if (!compilerConfiguration.isExcludedFromCompilation(file) && !isUnderRoots(processedRoots, file)) {
                    MavenModuleResourceConfiguration configuration = projectCfg.moduleConfigurations.get(module.getName());
                    if (configuration == null)
                        continue;
                    List<ResourceRootConfiguration> resourcesList = folder.isTestSource() ? configuration.testResources : configuration.resources;
                    final ResourceRootConfiguration cfg = new ResourceRootConfiguration();
                    cfg.directory = FileUtil.toSystemIndependentName(FileUtil.toSystemIndependentName(file.getPath()));
                    CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
                    if (compilerModuleExtension == null)
                        continue;
                    String compilerOutputUrl = folder.isTestSource() ? compilerModuleExtension.getCompilerOutputUrlForTests() : compilerModuleExtension.getCompilerOutputUrl();
                    cfg.targetPath = VfsUtilCore.urlToPath(compilerOutputUrl);
                    convertIdeaExcludesToMavenExcludes(cfg, (CompilerConfigurationImpl) compilerConfiguration);
                    resourcesList.add(cfg);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenResource(org.jetbrains.idea.maven.model.MavenResource) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration) Module(com.intellij.openapi.module.Module)

Example 2 with MavenResource

use of org.jetbrains.idea.maven.model.MavenResource in project intellij-community by JetBrains.

the class MavenDomUtil method getFilteredResourcesRoots.

private static Set<VirtualFile> getFilteredResourcesRoots(@NotNull MavenProject mavenProject) {
    Pair<Long, Set<VirtualFile>> cachedValue = mavenProject.getCachedValue(FILTERED_RESOURCES_ROOTS_KEY);
    if (cachedValue == null || cachedValue.first != VirtualFileManager.getInstance().getModificationCount()) {
        Set<VirtualFile> set = null;
        for (MavenResource resource : ContainerUtil.concat(mavenProject.getResources(), mavenProject.getTestResources())) {
            if (!resource.isFiltered())
                continue;
            VirtualFile resourceDir = LocalFileSystem.getInstance().findFileByPath(resource.getDirectory());
            if (resourceDir == null)
                continue;
            if (set == null) {
                set = new HashSet<>();
            }
            set.add(resourceDir);
        }
        if (set == null) {
            set = Collections.emptySet();
        }
        cachedValue = Pair.create(VirtualFileManager.getInstance().getModificationCount(), set);
        mavenProject.putCachedValue(FILTERED_RESOURCES_ROOTS_KEY, cachedValue);
    }
    return cachedValue.second;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) HashSet(java.util.HashSet) Set(java.util.Set) MavenResource(org.jetbrains.idea.maven.model.MavenResource)

Example 3 with MavenResource

use of org.jetbrains.idea.maven.model.MavenResource in project intellij-plugins by JetBrains.

the class ResourceCollector method getMavenResources.

private static List<MavenResource> getMavenResources(MavenProject currentProject) {
    List<MavenResource> resources = new ArrayList<>(currentProject.getResources());
    // also scan for any "packageinfo" files lurking in the source folders
    List<String> packageInfoIncludes = Collections.singletonList("**/packageinfo");
    for (String sourceRoot : currentProject.getSources()) {
        MavenResource packageInfoResource = new MavenResource(sourceRoot, false, null, packageInfoIncludes, null);
        resources.add(packageInfoResource);
    }
    return resources;
}
Also used : MavenResource(org.jetbrains.idea.maven.model.MavenResource)

Example 4 with MavenResource

use of org.jetbrains.idea.maven.model.MavenResource in project intellij-plugins by JetBrains.

the class ResourceCollector method getMavenResourcePaths.

private static String getMavenResourcePaths(@NotNull MavenProject currentProject) {
    Set<String> pathSet = new LinkedHashSet<>();
    for (MavenResource resource : getMavenResources(currentProject)) {
        final String sourcePath = resource.getDirectory();
        final String targetPath = resource.getTargetPath();
        // ignore empty or non-local resources
        if (new File(sourcePath).exists() && ((targetPath == null) || (!targetPath.contains("..")))) {
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(sourcePath);
            if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) {
                scanner.setIncludes(ArrayUtil.toStringArray(resource.getIncludes()));
            } else {
                scanner.setIncludes(DEFAULT_INCLUDES);
            }
            if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) {
                scanner.setExcludes(ArrayUtil.toStringArray(resource.getExcludes()));
            }
            scanner.addDefaultExcludes();
            scanner.scan();
            List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles());
            for (Object includedFile : includedFiles) {
                String name = (String) includedFile;
                String path = sourcePath + '/' + name;
                // this is a workaround for a problem with bnd 0.0.189
                if (File.separatorChar != '/') {
                    name = name.replace(File.separatorChar, '/');
                    path = path.replace(File.separatorChar, '/');
                }
                // copy to correct place
                path = name + '=' + path;
                if (targetPath != null) {
                    path = targetPath + '/' + path;
                }
                // use Bnd filtering?
                if (resource.isFiltered()) {
                    path = '{' + path + '}';
                }
                pathSet.add(path);
            }
        }
    }
    StringBuilder resourcePaths = new StringBuilder();
    for (Iterator<String> i = pathSet.iterator(); i.hasNext(); ) {
        resourcePaths.append(i.next());
        if (i.hasNext()) {
            resourcePaths.append(',');
        }
    }
    return resourcePaths.toString();
}
Also used : MavenResource(org.jetbrains.idea.maven.model.MavenResource) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) File(java.io.File)

Example 5 with MavenResource

use of org.jetbrains.idea.maven.model.MavenResource in project android by JetBrains.

the class AndroidMavenProviderImpl method processResources.

static boolean processResources(@NotNull Module module, @NotNull MavenProject mavenProject, ResourceProcessor processor) {
    for (MavenResource resource : mavenProject.getResources()) {
        if (resource.isFiltered()) {
            VirtualFile resDir = LocalFileSystem.getInstance().findFileByPath(resource.getDirectory());
            if (resDir == null)
                continue;
            List<Pattern> includes = collectPatterns(resource.getIncludes(), "**/*");
            List<Pattern> excludes = collectPatterns(resource.getExcludes(), null);
            final String resourceTargetPath = resource.getTargetPath();
            if (resourceTargetPath != null) {
                String targetPath = FileUtil.toSystemIndependentName(resourceTargetPath);
                if (processResources(module.getProject(), resDir, resDir, includes, excludes, targetPath, processor)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Pattern(java.util.regex.Pattern) MavenResource(org.jetbrains.idea.maven.model.MavenResource)

Aggregations

MavenResource (org.jetbrains.idea.maven.model.MavenResource)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 CompilerConfiguration (com.intellij.compiler.CompilerConfiguration)1 Module (com.intellij.openapi.module.Module)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 LinkedMultiMap (com.intellij.util.containers.LinkedMultiMap)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)1 JpsModuleSourceRootType (org.jetbrains.jps.model.module.JpsModuleSourceRootType)1