Java 类org.apache.maven.model.Resource 实例源码

项目:incubator-netbeans    文件:MavenNbModuleImpl.java   
@Override
public String getResourceDirectoryPath(boolean isTest) {
    NbMavenProject watch = project.getLookup().lookup(NbMavenProject.class);
    List<Resource> res;
    String defaultValue;

    if (isTest) {
        res = watch.getMavenProject().getTestResources();           
        defaultValue = "src/test/resources"; //NOI18N
    } else {
        res = watch.getMavenProject().getResources();
        defaultValue = "src/main/resources"; //NOI18N
    }
    for (Resource resource : res) {
        FileObject fo = FileUtilities.convertStringToFileObject(resource.getDirectory());
        if (fo != null && FileUtil.isParentOf(project.getProjectDirectory(), fo)) {
            return FileUtil.getRelativePath(project.getProjectDirectory(), fo);
        }
    }
    return defaultValue;
}
项目:syndesis    文件:GenerateMapperInspectionsMojo.java   
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {

        final Resource resource = new Resource();
        resource.setDirectory(outputDir.getCanonicalPath());
        project.addResource(resource);

        final Set<File> generated = new HashSet<>();

        final ReadApiClientData reader = new ReadApiClientData();
        final List<ModelData<?>> modelList = reader.readDataFromFile("io/syndesis/dao/deployment.json");
        for (final ModelData<?> model : modelList) {
            if (model.getKind() == Kind.Connector) {
                final Connector connector = (Connector) model.getData();

                for (final ConnectorAction action : connector.getActions()) {
                    process(generated, connector, action, action.getInputDataShape());
                    process(generated, connector, action, action.getOutputDataShape());
                }
            }
        }
    } catch (final IOException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
}
项目:featurea    文件:MavenUtil.java   
public static List<File> retrieveResourcesDirectories(List<File> contentRoots, List<MavenProject> allProjectsInBuild) {
    List<File> result = new ArrayList<>();
    for (MavenProject project : allProjectsInBuild) {
        String buildDirectory = formatPath(project.getBuild().getDirectory());
        for (Resource resource : project.getBuild().getResources()) {
            String contentRootPath = formatPath(resource.getDirectory());
            if (contentRootPath.startsWith(buildDirectory)) {
                continue;
            }
            File contentRoot = new File(contentRootPath);
            result.add(contentRoot);
        }
    }
    if (contentRoots != null) {
        result.addAll(contentRoots);
    }
    Iterator<File> iterator = result.iterator();
    while (iterator.hasNext()) {
        if (!iterator.next().exists()) {
            iterator.remove();
        }
    }
    return result;
}
项目:maven-seimicrawler-plugin    文件:WarProjectPackagingTask.java   
/**
 * @param webResources {@link #webResources}
 * @param webXml {@link #webXml}
 * @param containerConfigXml {@link #containerConfigXML}
 * @param currentProjectOverlay {@link #currentProjectOverlay}
 */
public WarProjectPackagingTask( Resource[] webResources, File webXml, File containerConfigXml,
                                Overlay currentProjectOverlay )
{
    if ( webResources != null )
    {
        this.webResources = webResources;
    }
    else
    {
        this.webResources = new Resource[0];
    }
    this.webXml = webXml;
    this.containerConfigXML = containerConfigXml;
    this.currentProjectOverlay = currentProjectOverlay;
    this.id = currentProjectOverlay.getId();
}
项目:maven-seimicrawler-plugin    文件:WarProjectPackagingTask.java   
/**
 * Returns a list of filenames that should be copied over to the destination directory.
 *
 * @param resource the resource to be scanned
 * @return the array of filenames, relative to the sourceDir
 */
private String[] getFilesToCopy( Resource resource )
{
    // CHECKSTYLE_OFF: LineLength
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir( resource.getDirectory() );
    if ( resource.getIncludes() != null && !resource.getIncludes().isEmpty() )
    {
        scanner.setIncludes( (String[]) resource.getIncludes().toArray( new String[resource.getIncludes().size()] ) );
    }
    else
    {
        scanner.setIncludes( DEFAULT_INCLUDES );
    }
    if ( resource.getExcludes() != null && !resource.getExcludes().isEmpty() )
    {
        scanner.setExcludes( (String[]) resource.getExcludes().toArray( new String[resource.getExcludes().size()] ) );
    }

    scanner.addDefaultExcludes();

    scanner.scan();

    return scanner.getIncludedFiles();
    // CHECKSTYLE_ON: LineLength
}
项目:vertx-forge-addon    文件:CustomResourceFacet.java   
@Override
public boolean install() {
  if (!this.isInstalled()) {
    getResourceDirectories().forEach(DirectoryResource::mkdirs);
  }

  // Update Maven model - main resource only
  MavenFacet maven = getFaceted().getFacet(MavenFacet.class);
  Model pom = maven.getModel();
  Resource main = new Resource();
  main.setDirectory("${project.basedir}/src/main/" + name);
  pom.getBuild().getResources().add(main);

  maven.setModel(pom);

  return true;
}
项目:Camel    文件:PackageHelper.java   
public static boolean haveResourcesChanged(Log log, MavenProject project, BuildContext buildContext, String suffix) {
    String baseDir = project.getBasedir().getAbsolutePath();
    for (Resource r : project.getBuild().getResources()) {
        File file = new File(r.getDirectory());
        if (file.isAbsolute()) {
            file = new File(r.getDirectory().substring(baseDir.length() + 1));
        }
        String path = file.getPath() + "/" + suffix;
        log.debug("checking  if " + path + " (" + r.getDirectory() + "/" + suffix + ") has changed.");
        if (buildContext.hasDelta(path)) {
            log.debug("Indeed " + suffix + " has changed.");
            return true;
        }
    }
    return false;
}
项目:Camel    文件:RunMojo.java   
@SuppressWarnings("unchecked")
private boolean detectBlueprintOnClassPathOrBlueprintXMLFiles() {
    List<Dependency> deps = project.getCompileDependencies();
    for (Dependency dep : deps) {
        if ("org.apache.camel".equals(dep.getGroupId()) && "camel-blueprint".equals(dep.getArtifactId())) {
            getLog().info("camel-blueprint detected on classpath");
        }
    }

    // maybe there is blueprint XML files
    List<Resource> resources = project.getResources();
    for (Resource res : resources) {
        File dir = new File(res.getDirectory());
        File xml = new File(dir, "OSGI-INF/blueprint");
        if (xml.exists() && xml.isDirectory()) {
            getLog().info("OSGi Blueprint XML files detected in directory " + xml);
            return true;
        }
    }

    return false;
}
项目:che    文件:MavenModelUtil.java   
private static List<MavenResource> convenrtResources(List<Resource> resources, File projectDir) {
  List<MavenResource> result = new ArrayList<>();
  if (resources != null) {
    for (Resource res : resources) {
      result.add(
          new MavenResource(
              relativize(projectDir, res.getDirectory()),
              res.isFiltering(),
              res.getTargetPath(),
              patternsOrEmptyList(res.getIncludes()),
              patternsOrEmptyList(res.getExcludes())));
    }
  }

  return result;
}
项目:crux-maven-plugin    文件:ClasspathBuilder.java   
/**
 * Get resources for specific scope.
 *
 * @param project
 * @param scope
 * @return
 */
private List<Resource> getResources(final MavenProject project, final String scope)
{
    if (SCOPE_COMPILE.equals(scope) || SCOPE_RUNTIME.equals(scope))
    {
        return project.getResources();
    }
    else if (SCOPE_TEST.equals(scope))
    {
        List<Resource> resources = new ArrayList<Resource>();
        resources.addAll(project.getTestResources());
        resources.addAll(project.getResources());
        return resources;
    }
    else
    {
        throw new RuntimeException("Not allowed scope " + scope);
    }
}
项目:jsweet-maven-plugin    文件:AbstractJSweetMojo.java   
@SuppressWarnings("unchecked")
protected SourceFile[] collectSourceFiles(MavenProject project) {

    logInfo("source includes: " + ArrayUtils.toString(includes));
    logInfo("source excludes: " + ArrayUtils.toString(excludes));

    List<String> sourcePaths = project.getCompileSourceRoots();
    logInfo("sources paths: " + sourcePaths);

    List<SourceFile> sources = new LinkedList<>();
    for (String sourcePath : sourcePaths) {
        scanForJavaFiles(sources, new File(sourcePath));
    }

    List<Resource> resources = project.getResources();
    logInfo("sources paths from resources: " + sourcePaths);

    for (Resource resource : resources) {
        String directory = resource.getDirectory();
        scanForJavaFiles(sources, new File(directory));
    }

    logInfo("sourceFiles=" + sources);

    return sources.toArray(new SourceFile[0]);
}
项目:jspresso-ce    文件:SjsMojo.java   
/**
 * Triggers thee execution of SJS compilation.
 *
 * @throws MojoExecutionException
 *     whenever an unexpected error occurs when executing mojo.
 */
@Override
public void execute() throws MojoExecutionException {
  if (isChangeDetected()) {
    try {
      runSjsCompilation();
    } catch (IOException | DependencyResolutionRequiredException | ScriptException | ResourceException ex) {
      throw new MojoExecutionException(
          "An unexpected exception occurred when running SJS compilation.", ex);
    }
  } else {
    getLog().info("No change detected. Skipping generation.");
  }
  Resource outputResource = new Resource();
  outputResource.setDirectory(outputDir.getPath());
  project.addResource(outputResource);
}
项目:build-helper-maven-plugin    文件:AbstractAddResourceMojo.java   
/**
 * Main plugin execution
 */
public void execute()
{
    for ( Resource resource : resources )
    {
        // Check for relative paths in the resource configuration.
        // http://maven.apache.org/plugin-developers/common-bugs.html#Resolving_Relative_Paths
        File resourceDir = new File( resource.getDirectory() );
        if ( !resourceDir.isAbsolute() )
        {
            resourceDir = new File( project.getBasedir(), resource.getDirectory() );
            resource.setDirectory( resourceDir.getAbsolutePath() );
        }

        addResource( resource );
    }
}
项目:hyperjaxb3    文件:Hyperjaxb3Mojo.java   
/**
 * Updates XJC's compilePath ans resources and update hyperjaxb2's
 * resources, that is, *.hbm.xml files and hibernate.config.xml file.
 * 
 * @param xjcOpts
 * @throws MojoExecutionException
 */
protected void setupMavenPaths() {
    super.setupMavenPaths();

    final Resource resource = new Resource();
    resource.setDirectory(getGenerateDirectory().getPath());
    for (String resourceInclude : resourceIncludes) {
        resource.addInclude(resourceInclude);
    }
    getProject().addResource(resource);

    if (this.roundtripTestClassName != null) {
        getProject().addTestCompileSourceRoot(
                getGenerateDirectory().getPath());
    }
}
项目:maven-tools    文件:RepositoryGenMojo.java   
private void copyResources() throws MojoExecutionException {
    List resources = project.getResources();
    if (resources != null) {
        getLog().info("Copying resources");
        for (Object obj : resources) {
            if (obj instanceof Resource) {
                Resource resource = (Resource) obj;
                try {
                    File resourceFolder = new File(resource.getDirectory());
                    if (resourceFolder.exists()) {
                        getLog().info("   " + resource.getDirectory());
                        FileManagementUtil.copyDirectory(resourceFolder, REPO_GEN_LOCATION);
                    }
                } catch (IOException e) {
                    throw new MojoExecutionException("Unable copy resources: " + resource.getDirectory(), e);
                }
            }
        }
    }
}
项目:camel-cdi    文件:RunMojo.java   
@SuppressWarnings("unchecked")
private boolean detectBlueprintOnClassPathOrBlueprintXMLFiles() {
    List<Dependency> deps = project.getCompileDependencies();
    for (Dependency dep : deps) {
        if ("org.apache.camel".equals(dep.getGroupId()) && "camel-blueprint".equals(dep.getArtifactId())) {
            getLog().info("camel-blueprint detected on classpath");
        }
    }

    // maybe there is blueprint XML files
    List<Resource> resources = project.getResources();
    for (Resource res : resources) {
        File dir = new File(res.getDirectory());
        File xml = new File(dir, "OSGI-INF/blueprint");
        if (xml.exists() && xml.isDirectory()) {
            getLog().info("OSGi Blueprint XML files detected in directory " + xml);
            return true;
        }
    }

    return false;
}
项目:proctor    文件:AbstractProctorMojo.java   
private void addNonPartialsToResources(final File dir, final Resource resource) throws CodeGenException {
    if (dir.equals(null)) {
        throw new CodeGenException("Could not read from directory " + dir.getPath());
    }
    final File[] files = dir.listFiles();
    if (files == null) {
        return;
    }
    for(File entry : files) {
        try {
            if (entry.isDirectory()) {
                addNonPartialsToResources(entry, resource);
            } else if (entry.getName().endsWith(".json") && ProctorUtils.readJsonFromFile(entry).has("tests")) {
                resource.addInclude(entry.getPath().substring(getTopDirectory().getPath().length() + 1));
            }
        } catch (IOException e) {
            throw new CodeGenException("Could not read from file " + entry.getName(),e);
        }

    }
}
项目:proctor    文件:AbstractProctorMojo.java   
Resource[] getResources() throws MojoExecutionException {
    final Resource resourceNonGenerated = new Resource();
    resourceNonGenerated.setDirectory(getTopDirectory().getPath());
    try {
        addNonPartialsToResources(getTopDirectory(),resourceNonGenerated);
    } catch (CodeGenException e) {
        throw new MojoExecutionException("Couldn't add non partial specifications to resources");
    }
    if (resourceNonGenerated.getIncludes().isEmpty()) {
        resourceNonGenerated.addExclude("**/*");
    }
    Resource resourceGenerated = new Resource();
    final File specificationOutputDir = getSpecificationOutput();
    resourceGenerated.setDirectory(specificationOutputDir.getPath());
    resourceGenerated.addInclude("**/*.json");
    final Resource[] resources = {resourceNonGenerated,resourceGenerated};
    return resources;

}
项目:wisdom    文件:MavenUtils.java   
/**
 * Compute a String form the given list of resources. The list is structured as follows:
 * list:=resource[,resource]*
 * resource:=directory;target;filtering;
 *
 * @param resources the list of resources
 * @return the computed String form
 */
protected static String toString(List<Resource> resources) {
    StringBuilder builder = new StringBuilder();

    for (Resource resource : resources) {
        if (builder.length() == 0) {
            builder.append(resource.getDirectory())
                    .append(";")
                    .append(resource.getTargetPath() != null ? resource.getTargetPath() : "")
                    .append(";")
                    .append(resource.getFiltering() != null ? resource.getFiltering() : "true")
                    .append(";");
        } else {
            builder.append(",")
                    .append(resource.getDirectory())
                    .append(";")
                    .append(resource.getTargetPath() != null ? resource.getTargetPath() : "")
                    .append(";")
                    .append(resource.getFiltering() != null ? resource.getFiltering() : "true")
                    .append(";");
        }
    }

    return builder.toString();
}
项目:wisdom    文件:ResourceCopy.java   
private static void filterAndCopy(AbstractWisdomMojo mojo, MavenResourcesFiltering filtering, File in, File out) throws IOException {
    Resource resource = new Resource();
    resource.setDirectory(in.getAbsolutePath());
    resource.setFiltering(true);
    resource.setTargetPath(out.getAbsolutePath());

    List<String> excludedExtensions = new ArrayList<>();
    excludedExtensions.addAll(filtering.getDefaultNonFilteredFileExtensions());
    excludedExtensions.addAll(NON_FILTERED_EXTENSIONS);

    MavenResourcesExecution exec = new MavenResourcesExecution(ImmutableList.of(resource), out, mojo.project,
            "UTF-8", Collections.<String>emptyList(), excludedExtensions, mojo.session);
    exec.setEscapeString("\\");

    try {
        filtering.filterResources(exec);
    } catch (MavenFilteringException e) {
        throw new IOException("Error while copying resources", e);
    }
}
项目:bpmn-miwg-tools    文件:ModelInterchangeMojoTest.java   
@Test
public void testMojoHandlingSchemaInvalidBpmn()
        throws XPathExpressionException, SAXException, IOException,
        MojoExecutionException {
    Resource res = new Resource();
    res.setDirectory("src/test/invalid-resources");
    mojo.resources.add(res);
    mojo.application = "Yaoqiang BPMN Editor 2.2.6";
    mojo.execute();

    assertTrue(overview.exists());
    Document document = docBuilder.parse(overview);

    XPathExpression xpath = createXpathExpression("//div[@class=\"test\" and @testcase=\"A.1.0\"  and contains(@tool, \"Yaoqiang\")]");
    NodeList nodes = (NodeList) xpath.evaluate(document,
            XPathConstants.NODESET);

    Node invalidNode = nodes.item(0);

    // There should be 2 findings: an invalid element and an invalid
    // attribute
    assertEquals("2",
            invalidNode.getAttributes().getNamedItem("data-xsd-finding")
                    .getNodeValue());
}
项目:rest-specs    文件:CatalogMojo.java   
public void execute() throws MojoExecutionException, MojoFailureException {

        final List<Resource> resources = project.getResources();
        final List<Path> sourceRoots = resources.stream()
                .map(Resource::getDirectory)
                .map(File::new)
                .map(File::toPath)
            .collect(Collectors.toList());

        final Path destinationRoot = new File(project.getBuild().getOutputDirectory()).toPath();

        try {
            CatalogUtility.generateCatalog(sourceRoots, destinationRoot, packageName);
        } catch (Exception e) {
            throw new MojoFailureException(String.format("cannot create catalog for '%s'", packageName), e);
        }


    }
项目:incubator-netbeans    文件:NbMavenProjectImpl.java   
public URI[] getResources(boolean test) {
        List<URI> toRet = new ArrayList<URI>();
        URI projectroot = getProjectDirectory().toURI();
        Set<URI> sourceRoots = null;
        List<Resource> res = test ? getOriginalMavenProject().getTestResources() : getOriginalMavenProject().getResources();
        LBL : for (Resource elem : res) {
            String dir = elem.getDirectory();
            if (dir == null) {
                continue; // #191742
            }
            URI uri = FileUtilities.getDirURI(getProjectDirectory(), dir);
            if (elem.getTargetPath() != null || !elem.getExcludes().isEmpty() || !elem.getIncludes().isEmpty()) {
                URI rel = projectroot.relativize(uri);
                if (rel.isAbsolute()) { //outside of project directory
                    continue;// #195928, #231517
                }
                if (sourceRoots == null) {
                    sourceRoots = new HashSet<URI>();
                    sourceRoots.addAll(Arrays.asList(getSourceRoots(true)));
                    sourceRoots.addAll(Arrays.asList(getSourceRoots(false)));
                    //should we also consider generated sources? most like not necessary
                }
                for (URI sr : sourceRoots) {
                    if (!uri.relativize(sr).isAbsolute()) {
                        continue LBL;// #195928, #231517
                    }
                }
                //hope for the best now
            }
//            if (new File(uri).exists()) {
            toRet.add(uri);
//            }
        }
        return toRet.toArray(new URI[toRet.size()]);
    }
项目:incubator-netbeans    文件:CopyResourcesOnSave.java   
final void refresh() {
    synchronized (resourceUris) {
        List<Resource> resources = new ArrayList<Resource>();
        resources.addAll(nbproject.getMavenProject().getResources());
        resources.addAll(nbproject.getMavenProject().getTestResources());
        Set<File> old = new HashSet<File>(resourceUris);
        Set<File> added = new HashSet<File>();

            for (Resource res : resources) {
                String dir = res.getDirectory();
                if (dir == null) {
                    continue;
                }
                URI uri = FileUtilities.getDirURI(project.getProjectDirectory(), dir);
                File file = Utilities.toFile(uri);
                if (!old.contains(file) && !added.contains(file)) { // if a given file is there multiple times, we get assertion back from FileUtil. there can be only one listener+file tuple
                    FileUtil.addRecursiveListener(this, file);
                }
                added.add(file);
            }

        old.removeAll(added);
        for (File oldFile : old) {
            FileUtil.removeRecursiveListener(this, oldFile);
        }
        resourceUris.removeAll(old);
        resourceUris.addAll(added);
    }
}
项目:incubator-netbeans    文件:CopyResourcesOnSave.java   
private String addTargetPath(String path, Resource resource) {
    String target = resource.getTargetPath();
    if (target != null) {
        target = target.replace("\\", "/");
        target = target.endsWith("/") ? target : (target + "/");
        path = target + path;
    }
    return path;
}
项目:incubator-netbeans    文件:CopyResourcesOnSave.java   
protected void logResources(FileObject fo, List<Resource> resources) {
    if(LOG.isLoggable(Level.FINE)) {
        for (Resource res : resources) {
            LOG.log(Level.FINE, " {0}", res);
        }
    }
}
项目:incubator-netbeans    文件:FilteredResourcesCoSSkipper.java   
private boolean hasChangedResources(Resource r, long stamp) {
        String dir = r.getDirectory();
        File dirFile = FileUtil.normalizeFile(new File(dir));
  //      System.out.println("checkresource dirfile =" + dirFile);
        if (dirFile.exists()) {
            List<File> toCopy = new ArrayList<File>();
            DirectoryScanner ds = new DirectoryScanner();
            ds.setBasedir(dirFile);
            //includes/excludes
            String[] incls = r.getIncludes().toArray(new String[0]);
            if (incls.length > 0) {
                ds.setIncludes(incls);
            } else {
                ds.setIncludes(DEFAULT_INCLUDES);
            }
            String[] excls = r.getExcludes().toArray(new String[0]);
            if (excls.length > 0) {
                ds.setExcludes(excls);
            }
            ds.addDefaultExcludes();
            ds.scan();
            String[] inclds = ds.getIncludedFiles();
//            System.out.println("found=" + inclds.length);
            for (String inc : inclds) {
                File f = new File(dirFile, inc);
                if (f.lastModified() >= stamp) { 
                    toCopy.add(FileUtil.normalizeFile(f));
                }
            }
            if (toCopy.size() > 0) {
                    //the case of filtering source roots, here we want to return false
                    //to skip CoS altogether.
                return true;
            }
        }
        return false;
    }
项目:incubator-netbeans    文件:OthersRootChildren.java   
@Override
@Messages({
    "# {0} - directory path",
    "TIP_Resource1=<html>Resource directory defined in POM.<br><i>Directory: </i><b>{0}</b><br>", 
    "# {0} - maven resource target path",
    "TIP_Resource2=<i>Target Path: </i><b>{0}</b><br>", 
    "# {0} - boolean value",
    "TIP_Resource6=<b><i>Filtering: </i>{0}. Please note that some IDE features rely on non-filtered content only.</b><br>", 
    "# {0} - includes string value",
    "TIP_Resource3=<i>Includes: </i><b>{0}</b><br>", 
    "# {0} - excludes string value",
    "TIP_Resource4=<i>Excludes: </i><b>{0}</b><br>", 
    "# {0} - directory path",
    "TIP_Resource5=<html>Configuration Directory<br><i>Directory: </i><b>{0}</b><br>"})
public String getShortDescription() {
    if (group.getResource() != null) {
        Resource rs = group.getResource();
        String str = TIP_Resource1(rs.getDirectory());
        if (rs.getTargetPath() != null) {
            str = str + TIP_Resource2(rs.getTargetPath());
        }
        if (rs.isFiltering()) {
            str = str + TIP_Resource6(rs.isFiltering());
        }
        if (rs.getIncludes() != null && rs.getIncludes().size() > 0) {
            str = str + TIP_Resource3(Arrays.toString(rs.getIncludes().toArray()));
        }
        if (rs.getExcludes() != null && rs.getExcludes().size() > 0) {
            str = str + TIP_Resource4(Arrays.toString(rs.getExcludes().toArray()));
        }
        return str;
    } else {
        return  TIP_Resource5(FileUtil.getFileDisplayName(group.getRootFolder()));
     }
}
项目:incubator-netbeans    文件:MavenSourcesImpl.java   
private Resource checkResource(FileObject rootFold, List<Resource> list) {
    for (Resource elem : list) {
        String dir = elem.getDirectory();
        if (dir == null) { // #203635
            continue;
        }
        URI uri = FileUtilities.getDirURI(project.getProjectDirectory(), dir);
        FileObject fo = FileUtilities.convertURItoFileObject(uri);
        if (fo != null && fo.equals(rootFold)) {
            return elem;
        }
    }
    return null;
}
项目:azure-maven-plugins    文件:FTPArtifactHandlerImpl.java   
protected void copyResourcesToStageDirectory(final List<Resource> resources) throws IOException {
    Utils.copyResources(mojo.getProject(),
            mojo.getSession(),
            mojo.getMavenResourcesFiltering(),
            resources,
            mojo.getDeploymentStageDirectory());
}
项目:azure-maven-plugins    文件:DeployMojo.java   
protected void deployArtifacts() throws Exception {
    final List<Resource> resources = getResources();
    if (resources == null || resources.isEmpty()) {
        info(NO_RESOURCES_CONFIG);
    } else {
        try {
            util.beforeDeployArtifacts();
            getFactory().getArtifactHandler(this).publish(resources);
        } finally {
            util.afterDeployArtifacts();
        }
    }
}
项目:azure-maven-plugins    文件:DeployMojoTest.java   
@Test
public void deployArtifactsWithResources() throws Exception {
    final DeployMojo mojo = getMojoFromPom("/pom-linux.xml");
    final DeployMojo mojoSpy = spy(mojo);
    doReturn(getResourceList()).when(mojoSpy).getResources();

    mojoSpy.deployArtifacts();

    verify(artifactHandler, times(1)).publish(ArgumentMatchers.<Resource>anyList());
    verifyNoMoreInteractions(artifactHandler);
}
项目:azure-maven-plugins    文件:DeployMojoTest.java   
private List<Resource> getResourceList() {
    final Resource resource = new Resource();
    resource.setDirectory("/");
    resource.setTargetPath("/");

    final List<Resource> resources = new ArrayList<>();
    resources.add(resource);

    return resources;
}
项目:azure-maven-plugins    文件:FTPArtifactHandlerImplTest.java   
@Test
public void publish() throws Exception {
    final FTPArtifactHandlerImpl handlerSpy = spy(handler);
    doNothing().when(handlerSpy).copyResourcesToStageDirectory(ArgumentMatchers.<Resource>anyList());
    doNothing().when(handlerSpy).uploadDirectoryToFTP();

    handlerSpy.publish(new ArrayList<Resource>());
    verify(handlerSpy, times(1))
            .copyResourcesToStageDirectory(ArgumentMatchers.<Resource>anyList());
    verify(handlerSpy, times(1)).uploadDirectoryToFTP();
}
项目:azure-maven-plugins    文件:FTPArtifactHandlerImplTest.java   
@Test
public void copyResourcesToStageDirectory() throws Exception {
    doReturn(mock(MavenProject.class)).when(mojo).getProject();
    doReturn(mock(MavenSession.class)).when(mojo).getSession();
    doReturn(mock(MavenResourcesFiltering.class)).when(mojo).getMavenResourcesFiltering();
    doReturn("stageDirectory").when(mojo).getDeploymentStageDirectory();

    handler.copyResourcesToStageDirectory(new ArrayList<Resource>());
    verify(mojo, times(1)).getProject();
    verify(mojo, times(1)).getSession();
    verify(mojo, times(1)).getMavenResourcesFiltering();
    verify(mojo, times(1)).getDeploymentStageDirectory();
    verifyNoMoreInteractions(mojo);
}
项目:azure-maven-plugins    文件:Utils.java   
/**
 * Copy resources to target directory using Maven resource filtering so that we don't have to handle
 * recursive directory listing and pattern matching.
 * In order to disable filtering, the "filtering" property is force set to False.
 *
 * @param project
 * @param session
 * @param filtering
 * @param resources
 * @param targetDirectory
 * @throws IOException
 */
public static void copyResources(final MavenProject project, final MavenSession session,
                                 final MavenResourcesFiltering filtering, final List<Resource> resources,
                                 final String targetDirectory) throws IOException {
    for (final Resource resource : resources) {
        resource.setTargetPath(Paths.get(targetDirectory, resource.getTargetPath()).toString());
        resource.setFiltering(false);
    }

    final MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(
            resources,
            new File(targetDirectory),
            project,
            "UTF-8",
            null,
            Collections.EMPTY_LIST,
            session
    );

    // Configure executor
    mavenResourcesExecution.setEscapeWindowsPaths(true);
    mavenResourcesExecution.setInjectProjectBuildFilters(false);
    mavenResourcesExecution.setOverwrite(true);
    mavenResourcesExecution.setIncludeEmptyDirs(false);
    mavenResourcesExecution.setSupportMultiLineFiltering(false);

    // Filter resources
    try {
        filtering.filterResources(mavenResourcesExecution);
    } catch (MavenFilteringException ex) {
        throw new IOException("Failed to copy resources", ex);
    }
}
项目:azure-maven-plugins    文件:UtilsTest.java   
@Test
public void copyResources() throws Exception {
    final MavenResourcesFiltering filtering = mock(MavenResourcesFiltering.class);
    final Resource resource = new Resource();
    resource.setTargetPath("/");

    Utils.copyResources(mock(MavenProject.class),
            mock(MavenSession.class),
            filtering,
            Arrays.asList(new Resource[] {resource}),
            "target");
    verify(filtering, times(1)).filterResources(any(MavenResourcesExecution.class));
    verifyNoMoreInteractions(filtering);
}
项目:azure-maven-plugins    文件:PackageMojo.java   
protected List<Resource> getResources() {
    final Resource resource = new Resource();
    resource.setDirectory(getBuildDirectoryAbsolutePath());
    resource.setTargetPath("/");
    resource.setFiltering(false);
    resource.setIncludes(Arrays.asList("*.jar"));
    return Arrays.asList(resource);
}
项目:apache-maven-shade-plugin    文件:MavenJDOMWriter.java   
/**
 * Method updateResource
 *
 * @param value
 * @param element
 * @param counter
 * @param xmlTag
 */
protected void updateResource( Resource value, String xmlTag, Counter counter, Element element )
{
    Element root = element;
    Counter innerCount = new Counter( counter.getDepth() + 1 );
    findAndReplaceSimpleElement( innerCount, root, "targetPath", value.getTargetPath(), null );
    findAndReplaceSimpleElement( innerCount, root, "filtering",
                                 !value.isFiltering() ? null : String.valueOf( value.isFiltering() ), "false" );
    findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
    findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
    findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
}
项目:maven-seimicrawler-plugin    文件:WarProjectPackagingTask.java   
/**
 * Handles the web resources.
 *
 * @param context the packaging context
 * @throws MojoExecutionException if a resource could not be copied
 */
protected void handleWebResources( WarPackagingContext context )
    throws MojoExecutionException
{
    for ( Resource resource : webResources )
    {

        // MWAR-246
        if ( resource.getDirectory() == null )
        {
            throw new MojoExecutionException( "The <directory> tag is missing from the <resource> tag." );
        }

        if ( !( new File( resource.getDirectory() ) ).isAbsolute() )
        {
            resource.setDirectory( context.getProject().getBasedir() + File.separator + resource.getDirectory() );
        }

        // Make sure that the resource directory is not the same as the webappDirectory
        if ( !resource.getDirectory().equals( context.getWebappDirectory().getPath() ) )
        {

            try
            {
                copyResources( context, resource );
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException( "Could not copy resource [" + resource.getDirectory() + "]", e );
            }
        }
    }
}