Example usage for org.apache.commons.io FileUtils copyFileToDirectory

List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils copyFileToDirectory.

Prototype

public static void copyFileToDirectory(File srcFile, File destDir) throws IOException 

Source Link

Document

Copies a file to a directory preserving the file date.

Usage

From source file:de.uzk.hki.da.convert.PublishPDFConversionStrategy.java

@Override
public List<Event> convertFile(WorkArea wa, ConversionInstruction ci) throws IOException {

    if (ci.getConversion_routine() == null)
        throw new IllegalStateException("conversionRoutine not set");
    if (ci.getConversion_routine().getTarget_suffix().isEmpty())
        throw new IllegalStateException("target suffix in conversionRoutine not set");

    List<Event> results = new ArrayList<Event>();

    String input = wa.toFile(ci.getSource_file()).getAbsolutePath();

    for (String audience : audiences) {

        String audience_lc = audience.toLowerCase();

        DAFile target = new DAFile(pips + "/" + audience_lc, StringUtilities.slashize(ci.getTarget_folder())
                + FilenameUtils.getBaseName(input) + "." + ci.getConversion_routine().getTarget_suffix());
        wa.toFile(target).getParentFile().mkdirs();

        String numberOfPagesText = null;
        if (getPublicationRightForAudience(audience) != null)
            if (getPublicationRightForAudience(audience).getTextRestriction() != null)
                if (getPublicationRightForAudience(audience).getTextRestriction().getPages() != null)
                    numberOfPagesText = getPublicationRightForAudience(audience).getTextRestriction().getPages()
                            .toString();

        String certainPagesText = null;
        if (getPublicationRightForAudience(audience) != null) {
            certainPagesText = "";
            if (getPublicationRightForAudience(audience).getTextRestriction() != null)
                if (getPublicationRightForAudience(audience).getTextRestriction().getCertainPages() != null)
                    for (int i = 0; i < getPublicationRightForAudience(audience).getTextRestriction()
                            .getCertainPages().length; i++) {
                        if (!certainPagesText.equals(""))
                            certainPagesText += " ";
                        certainPagesText += getPublicationRightForAudience(audience).getTextRestriction()
                                .getCertainPages()[i];
                    }/*from w w  w. j  a v a2 s.  com*/
        }

        // copy whole file if no restrictions are found
        if (StringUtilities.isNotSet(numberOfPagesText) && StringUtilities.isNotSet(certainPagesText)) {
            try {
                logger.debug("AUDIENCE " + audience + ": COPY " + input + " to " + target);
                FileUtils.copyFileToDirectory(new File(input), wa.toFile(target).getParentFile());
                Event e = new Event();
                e.setDetail("Copied PDF");
                e.setSource_file(ci.getSource_file());
                e.setTarget_file(target);
                e.setType("CONVERT");
                e.setDate(new Date());
                results.add(e);
            } catch (IOException e) {
                throw new RuntimeException("Could not copy PDF!", e);
            }
            continue;
        }
        logger.debug("AUDIENCE " + audience
                + ": Converted with PDFBox, only certain pages wanted: NumberOfPagesMax:(" + numberOfPagesText
                + "), CertainPages:(" + certainPagesText + ")");
        PdfService pdf = new PdfService(new File(input), wa.toFile(target));
        pdf.reduceToCertainPages(numberOfPagesText, certainPagesText);
        Event e = new Event();
        e.setDetail("converted with PDFBox");
        e.setSource_file(ci.getSource_file());
        e.setTarget_file(target);
        e.setType("CONVERT");
        e.setDate(new Date());
        results.add(e);
    }
    return results;

}

From source file:com.lohika.alp.reporter.ResultsXML2HTML.java

protected void transformLogs(List<ISuite> suites, String outputDirectory)
        throws IOException, TransformerException {

    // HTML logs output directory
    File logsHtml = new File(outputDirectory, logsHtmlDir);

    // HTML data output directory
    File logsData = new File(outputDirectory, logsDataDir);

    // XSL file (extracted to logs-data)
    File xsl = new File(logsData, logHtmlXslName);

    // Relative path from HTML logs to logs-data directory
    String relative = "../" + logsDataDir;

    if (!logsHtml.exists())
        logsHtml.mkdir();/*from   w ww.j a  v  a  2s. c o m*/

    if (!logsData.exists())
        logsData.mkdir();

    // Copy logs-data from resources to output directory
    Resources resources = new Resources();
    resources.copy(getClass(), logsDataDir + "/", logsData);

    HTMLLogTransformer transformer = new HTMLLogTransformer(xsl, relative);

    // Transform to HTML logs for each test result
    for (ISuite suite : suites) {
        for (ISuiteResult test : suite.getResults().values()) {

            List<ITestResult> results = helper.getAllTestResults(test);

            for (ITestResult result : results) {
                // Get XML log file stored as ITestResult attribute
                File xml = LogFileAttribute.getLogFile(result);

                if (xml != null) {
                    // Using name of XML log for HTML log
                    String name = xml.getName().replace(".xml", "");

                    // Set HTML file extension
                    name = name + ".html";
                    File html = new File(logsHtml, name);

                    transformer.transform(xml, html);
                }

                // Copy log attachments
                List<File> attachments = LogFileAttachmentAttribute.getAttachmentFiles(result);

                if (attachments != null) {
                    for (File attachment : attachments) {
                        FileUtils.copyFileToDirectory(attachment, logsHtml);
                    }
                }
            }
        }
    }
}

From source file:net.sourceforge.ganttproject.gui.options.InterfaceOptionPageProvider.java

private static Pair<Boolean, File> checkLocale(Locale l) {
    if (Arrays.asList(DateFormat.getAvailableLocales()).contains(l)) {
        return Pair.create(Boolean.TRUE, null);
    }/*from  www. j  ava2  s.co m*/
    File extDir = getExtDir();
    if (!extDir.exists()) {
        return Pair.create(Boolean.FALSE, null);
    }
    if (!extDir.isDirectory()) {
        return Pair.create(Boolean.FALSE, null);
    }
    if (extDir.canWrite()) {
        GPLogger.logToLogger("Java extensions directory " + extDir + " is writable");
        URL libUrl = InterfaceOptionPageProvider.class.getResource("lib");
        if (libUrl != null) {
            try {
                File galicianLocaleJar = new File(new File(libUrl.toURI()), "javagalician.jar");
                File targetJar = new File(extDir, galicianLocaleJar.getName());
                GPLogger.logToLogger("Locale extension " + galicianLocaleJar);
                if (galicianLocaleJar.exists() && !targetJar.exists()) {
                    GPLogger.logToLogger("Exists. Installing now");
                    FileUtils.copyFileToDirectory(galicianLocaleJar, extDir);
                    return Pair.create(Boolean.TRUE, extDir);
                }
            } catch (IOException e) {
                GPLogger.log(e);
            } catch (URISyntaxException e) {
                GPLogger.log(e);
            }
        }
        return Pair.create(Boolean.FALSE, extDir);
    } else {
        GPLogger.logToLogger("Java extensions directory " + extDir + " is not writable");
    }
    return Pair.create(Boolean.FALSE, extDir);
}

From source file:com.igormaznitsa.mvngolang.GolangMvnInstallMojo.java

@Nonnull
private File compressProjectFiles() throws IOException {
    final Artifact artifact = this.project.getArtifact();
    final File resultZip = new File(this.project.getBuild().getDirectory(),
            artifact.getArtifactId() + '-' + artifact.getVersion() + '.' + artifact.getType());
    if (resultZip.isFile() && !resultZip.delete()) {
        throw new IOException("Can't delete file : " + resultZip);
    }// w  w w . j  a va 2 s . co  m

    final File folderToPack = new File(
            ".tmp_pack_folder_" + Long.toHexString(System.currentTimeMillis()).toUpperCase(Locale.ENGLISH));
    if (folderToPack.isDirectory()) {
        FileUtils.deleteDirectory(folderToPack);
    }
    if (!folderToPack.mkdirs()) {
        throw new IOException("Can't create temp folder : " + folderToPack);
    }

    try {
        saveEffectivePom(folderToPack);

        FileUtils.copyFileToDirectory(this.project.getFile(), folderToPack);
        safeCopyDirectory(this.project.getBuild().getSourceDirectory(), folderToPack);
        safeCopyDirectory(this.project.getBuild().getTestSourceDirectory(), folderToPack);

        for (final Resource res : this.project.getBuild().getResources()) {
            safeCopyDirectory(res.getDirectory(), folderToPack);
        }

        for (final Resource res : this.project.getBuild().getTestResources()) {
            safeCopyDirectory(res.getDirectory(), folderToPack);
        }

        if (getLog().isDebugEnabled()) {
            getLog().debug(String.format("Packing folder %s to %s", folderToPack.getAbsolutePath(),
                    resultZip.getAbsolutePath()));
        }

        ZipUtil.pack(folderToPack, resultZip, Math.min(9, Math.max(1, this.compression)));

    } finally {
        FileUtils.deleteQuietly(folderToPack);
    }

    return resultZip;
}

From source file:ddf.security.pdp.xacml.processor.BalanaPdpTest.java

@Test
public void testEvaluate_role_user_action_query_citizenship_US() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_US");

    // Setup/*from  w  ww  . j  av  a 2s .  c o m*/
    File destDir = folder.newFolder(TEMP_DIR_NAME);
    LOGGER.debug("Making directory: " + destDir.getPath());
    destDir.mkdir();
    File srcFile = new File(
            PROJECT_HOME + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
    FileUtils.copyFileToDirectory(srcFile, destDir);

    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);

    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    actionValue.getContent().add(QUERY_ACTION);
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);

    AttributesType subjectAttributes = new AttributesType();
    subjectAttributes.setCategory(SUBJECT_CATEGORY);
    AttributeType subjectAttribute = new AttributeType();
    subjectAttribute.setAttributeId(SUBJECT_ID);
    subjectAttribute.setIncludeInResult(false);
    AttributeValueType subjectValue = new AttributeValueType();
    subjectValue.setDataType(STRING_DATA_TYPE);
    subjectValue.getContent().add(TEST_USER_1);
    subjectAttribute.getAttributeValue().add(subjectValue);
    subjectAttributes.getAttribute().add(subjectAttribute);

    AttributeType roleAttribute = new AttributeType();
    roleAttribute.setAttributeId(ROLE_CLAIM);
    roleAttribute.setIncludeInResult(false);
    AttributeValueType roleValue = new AttributeValueType();
    roleValue.setDataType(STRING_DATA_TYPE);
    roleValue.getContent().add(ROLE);
    roleAttribute.getAttributeValue().add(roleValue);
    subjectAttributes.getAttribute().add(roleAttribute);

    AttributesType categoryAttributes = new AttributesType();
    categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
    AttributeType citizenshipAttribute = new AttributeType();
    citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
    citizenshipAttribute.setIncludeInResult(false);
    AttributeValueType citizenshipValue = new AttributeValueType();
    citizenshipValue.setDataType(STRING_DATA_TYPE);
    citizenshipValue.getContent().add(US_COUNTRY);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);

    xacmlRequestType.getAttributes().add(actionAttributes);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    xacmlRequestType.getAttributes().add(categoryAttributes);

    BalanaPdp pdp = new BalanaPdp(destDir);

    // Perform Test
    ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);

    // Verify
    JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
    LOGGER.debug("\nXACML 3.0 Response:\n" + writer.toString());
    assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);

    // Cleanup
    LOGGER.debug("Deleting directory: " + destDir);
    FileUtils.deleteDirectory(destDir);
}

From source file:ddf.security.pdp.realm.xacml.processor.XacmlClientTest.java

@Test
public void testEvaluateroleuseractionquerycitizenshipUS() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_US");

    // Setup//from w  ww.j a v a  2s  .  c  o  m
    File destDir = folder.newFolder(TEMP_DIR_NAME);
    LOGGER.debug("Making directory: {}", destDir.getPath());
    if (destDir.mkdir()) {
        File srcFile = new File(
                projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
        FileUtils.copyFileToDirectory(srcFile, destDir);

        RequestType xacmlRequestType = new RequestType();
        xacmlRequestType.setCombinedDecision(false);
        xacmlRequestType.setReturnPolicyIdList(false);

        AttributesType actionAttributes = new AttributesType();
        actionAttributes.setCategory(ACTION_CATEGORY);
        AttributeType actionAttribute = new AttributeType();
        actionAttribute.setAttributeId(ACTION_ID);
        actionAttribute.setIncludeInResult(false);
        AttributeValueType actionValue = new AttributeValueType();
        actionValue.setDataType(STRING_DATA_TYPE);
        actionValue.getContent().add(QUERY_ACTION);
        actionAttribute.getAttributeValue().add(actionValue);
        actionAttributes.getAttribute().add(actionAttribute);

        AttributesType subjectAttributes = new AttributesType();
        subjectAttributes.setCategory(SUBJECT_CATEGORY);
        AttributeType subjectAttribute = new AttributeType();
        subjectAttribute.setAttributeId(SUBJECT_ID);
        subjectAttribute.setIncludeInResult(false);
        AttributeValueType subjectValue = new AttributeValueType();
        subjectValue.setDataType(STRING_DATA_TYPE);
        subjectValue.getContent().add(TEST_USER_1);
        subjectAttribute.getAttributeValue().add(subjectValue);
        subjectAttributes.getAttribute().add(subjectAttribute);

        AttributeType roleAttribute = new AttributeType();
        roleAttribute.setAttributeId(ROLE_CLAIM);
        roleAttribute.setIncludeInResult(false);
        AttributeValueType roleValue = new AttributeValueType();
        roleValue.setDataType(STRING_DATA_TYPE);
        roleValue.getContent().add(ROLE);
        roleAttribute.getAttributeValue().add(roleValue);
        subjectAttributes.getAttribute().add(roleAttribute);

        AttributesType categoryAttributes = new AttributesType();
        categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
        AttributeType citizenshipAttribute = new AttributeType();
        citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
        citizenshipAttribute.setIncludeInResult(false);
        AttributeValueType citizenshipValue = new AttributeValueType();
        citizenshipValue.setDataType(STRING_DATA_TYPE);
        citizenshipValue.getContent().add(US_COUNTRY);
        citizenshipAttribute.getAttributeValue().add(citizenshipValue);
        categoryAttributes.getAttribute().add(citizenshipAttribute);

        xacmlRequestType.getAttributes().add(actionAttributes);
        xacmlRequestType.getAttributes().add(subjectAttributes);
        xacmlRequestType.getAttributes().add(categoryAttributes);

        XacmlClient pdp = new XacmlClient(destDir.getCanonicalPath(), new XmlParser());

        // Perform Test
        ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);

        // Verify
        JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        ObjectFactory objectFactory = new ObjectFactory();
        Writer writer = new StringWriter();
        marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
        LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
        assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);

        // Cleanup
        LOGGER.debug("Deleting directory: " + destDir);
        FileUtils.deleteDirectory(destDir);
    } else {
        LOGGER.debug("Could not create directory: " + destDir);
    }
}

From source file:ddf.security.pdp.realm.xacml.processor.BalanaClientTest.java

@Test
public void testEvaluateroleuseractionquerycitizenshipUS() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_US");

    // Setup//from   w w w.j a  v  a2s . co m
    File destDir = folder.newFolder(TEMP_DIR_NAME);
    LOGGER.debug("Making directory: {}", destDir.getPath());
    if (destDir.mkdir()) {
        File srcFile = new File(
                projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
        FileUtils.copyFileToDirectory(srcFile, destDir);

        RequestType xacmlRequestType = new RequestType();
        xacmlRequestType.setCombinedDecision(false);
        xacmlRequestType.setReturnPolicyIdList(false);

        AttributesType actionAttributes = new AttributesType();
        actionAttributes.setCategory(ACTION_CATEGORY);
        AttributeType actionAttribute = new AttributeType();
        actionAttribute.setAttributeId(ACTION_ID);
        actionAttribute.setIncludeInResult(false);
        AttributeValueType actionValue = new AttributeValueType();
        actionValue.setDataType(STRING_DATA_TYPE);
        actionValue.getContent().add(QUERY_ACTION);
        actionAttribute.getAttributeValue().add(actionValue);
        actionAttributes.getAttribute().add(actionAttribute);

        AttributesType subjectAttributes = new AttributesType();
        subjectAttributes.setCategory(SUBJECT_CATEGORY);
        AttributeType subjectAttribute = new AttributeType();
        subjectAttribute.setAttributeId(SUBJECT_ID);
        subjectAttribute.setIncludeInResult(false);
        AttributeValueType subjectValue = new AttributeValueType();
        subjectValue.setDataType(STRING_DATA_TYPE);
        subjectValue.getContent().add(TEST_USER_1);
        subjectAttribute.getAttributeValue().add(subjectValue);
        subjectAttributes.getAttribute().add(subjectAttribute);

        AttributeType roleAttribute = new AttributeType();
        roleAttribute.setAttributeId(ROLE_CLAIM);
        roleAttribute.setIncludeInResult(false);
        AttributeValueType roleValue = new AttributeValueType();
        roleValue.setDataType(STRING_DATA_TYPE);
        roleValue.getContent().add(ROLE);
        roleAttribute.getAttributeValue().add(roleValue);
        subjectAttributes.getAttribute().add(roleAttribute);

        AttributesType categoryAttributes = new AttributesType();
        categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
        AttributeType citizenshipAttribute = new AttributeType();
        citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
        citizenshipAttribute.setIncludeInResult(false);
        AttributeValueType citizenshipValue = new AttributeValueType();
        citizenshipValue.setDataType(STRING_DATA_TYPE);
        citizenshipValue.getContent().add(US_COUNTRY);
        citizenshipAttribute.getAttributeValue().add(citizenshipValue);
        categoryAttributes.getAttribute().add(citizenshipAttribute);

        xacmlRequestType.getAttributes().add(actionAttributes);
        xacmlRequestType.getAttributes().add(subjectAttributes);
        xacmlRequestType.getAttributes().add(categoryAttributes);

        BalanaClient pdp = new BalanaClient(destDir.getCanonicalPath(), new XmlParser());

        // Perform Test
        ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);

        // Verify
        JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        ObjectFactory objectFactory = new ObjectFactory();
        Writer writer = new StringWriter();
        marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
        LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
        assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);

        // Cleanup
        LOGGER.debug("Deleting directory: " + destDir);
        FileUtils.deleteDirectory(destDir);
    } else {
        LOGGER.debug("Could not create directory: " + destDir);
    }
}

From source file:com.photon.phresco.plugins.WordPressPackage.java

private boolean build() throws MojoExecutionException {
    boolean isBuildSuccess = true;
    try {/* w ww  .  ja  v  a  2s. co m*/
        configure();
        File[] listSourceFiles = srcDir.listFiles();
        for (File childFile : listSourceFiles) {
            if (childFile.isDirectory()) {
                FileUtils.copyDirectoryToDirectory(childFile, targetDir);
            } else {
                FileUtils.copyFileToDirectory(childFile, targetDir);
            }
        }
        createPackage();

    } catch (IOException e) {
        isBuildSuccess = false;
        getLog().error(e);
        throw new MojoExecutionException(e.getMessage(), e);
    }
    return isBuildSuccess;
}

From source file:info.magnolia.cms.gui.fckeditor.FCKEditorSimpleUploadServlet.java

/**
 * Manage the Upload requests.<br>
 * The servlet accepts commands sent in the following format:<br>
 * simpleUploader?Type=ResourceType<br>
 * <br>/*from   w  w  w .j a v  a  2 s  .  co  m*/
 * It store the file (renaming it in case a file with the same name exists) and then return an HTML file with a
 * javascript command in it.
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    super.doPost(request, response);
    response.setContentType("text/html; charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    PrintWriter out = response.getWriter();

    String typeStr = request.getParameter("type");

    String retVal = "0";
    String newName = "";
    String fileUrl = "";
    String errorMessage = "";

    RequestFormUtil form = new RequestFormUtil(request);

    Document doc = form.getDocument("NewFile");

    if (extIsAllowed(typeStr, doc.getExtension())) {

        try {
            // now copy the files to the special fck tmp folder
            String uuid = UUIDGenerator.getInstance().generateTimeBasedUUID().toString();
            FileUtils.copyFileToDirectory(doc.getFile(),
                    new File(Path.getTempDirectoryPath() + "/fckeditor/" + uuid));
            doc.delete();

            // the document will now point to the copied file
            doc = new Document(
                    new File(
                            Path.getTempDirectoryPath() + "/fckeditor/" + uuid + "/" + doc.getFile().getName()),
                    doc.getType());

            // save it to the session
            FCKEditorTmpFiles.addDocument(doc, uuid);

            // make the temporary url ready for the editor
            fileUrl = request.getContextPath() + "/tmp/fckeditor/" + uuid + "/" + doc.getFile().getName();

        } catch (Exception ex) {
            log.error("can't upload the file", ex);
            retVal = "203";
        }

    } else {
        log.info("Tried to upload a not allowed file [" + doc.getFileNameWithExtension() + "]");
        retVal = "202";
        errorMessage = "";
    }

    out.println("<script type=\"text/javascript\">");
    out.println("window.parent.OnUploadCompleted(" + retVal + ",'" + fileUrl + "','" + newName + "','"
            + errorMessage + "');");
    out.println("</script>");
    out.flush();
    out.close();
}

From source file:hudson.plugins.mstest.MSTestPublisherJenkinsRuleTest.java

@Test
public void testExecuteOnRealTrx_usingAntFileSet() throws InterruptedException, IOException, Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    project.getPublishersList().add(new MSTestPublisher("**/*.trx"));
    project.getBuildersList().add(new TestBuilder() {
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
                throws InterruptedException, IOException {
            File f = new File("src/test/resources/hudson/plugins/mstest/results-example-mstest.trx");
            assertTrue(f.exists());/*from  w w  w .  j av  a  2  s  .com*/
            File dest = new File(build.getWorkspace().getRemote(),
                    "TestResults_51310ef0-5d36-47cc-a1a9-b21d6f3e2072");
            assertTrue(dest.mkdir());
            FileUtils.copyFileToDirectory(f, dest);
            assertTrue(build.getWorkspace()
                    .child("TestResults_51310ef0-5d36-47cc-a1a9-b21d6f3e2072/results-example-mstest.trx")
                    .exists());
            return true;
        }
    });

    FreeStyleBuild build = project.scheduleBuild2(0).get();
    if (build != null) {
        String s = FileUtils.readFileToString(build.getLogFile());
        assertTrue(s == null || s.contains(File.separator + "results-example-mstest.trx"));
    }
}