Package org.moxie

Examples of org.moxie.Build


  }


  @Override
  public void execute() {
    Build build = (Build) getProject().getReference(Key.build.referenceId());
    console = build.getConsole();
    if (main == null && mainJars == null) {
      manifestSet = true;
      Main main = new Main();
      main.setProject(getProject());

      if (excludes == null) {
        excludes = Toolkit.DEFAULT_CODE_EXCLUDES;
      }

      // compiled output of this project
      File outputFolder = build.getConfig().getOutputDirectory(Scope.compile);
      ZipFileSet outputSet = new ZipFileSet();
      outputSet.setProject(getProject());
      outputSet.setDir(outputFolder);
      if (includes != null) {
        outputSet.setIncludes(includes);
      }
      outputSet.setExcludes(excludes);
      main.addFileSet(outputSet);

      // add the output and resource folders of modules
      for (Build module : build.getSolver().getLinkedModules()) {
        ZipFileSet projectOutputSet = new ZipFileSet();
        projectOutputSet.setProject(getProject());
        File dir = module.getConfig().getOutputDirectory(Scope.compile);
        projectOutputSet.setDir(dir);
        if (includes != null) {
          projectOutputSet.setIncludes(includes);
        }
        projectOutputSet.setExcludes(excludes);
        main.addFileSet(projectOutputSet);

        if (includeResources) {
          // add linked module resources
          for (File resDir : module.getConfig().getResourceDirectories(Scope.compile)) {
            ZipFileSet resSet = new ZipFileSet();
            resSet.setProject(getProject());
            resSet.setDir(resDir);
            resSet.setExcludes(Toolkit.DEFAULT_RESOURCE_EXCLUDES);
            main.addFileSet(resSet);
          }
        }
      }

      // resource directories
      if (includeResources) {
        for (File dir : build.getConfig().getResourceDirectories(Scope.compile, tag)) {
          ZipFileSet set = new ZipFileSet();
          set.setProject(getProject());
          set.setDir(dir);
          set.setExcludes(Toolkit.DEFAULT_RESOURCE_EXCLUDES);
          main.addFileSet(set);
        }
      }

      createDependencies().setTag(tag);

      if (getDestFile() == null) {
        setDestFile(build.getBuildArtifact(classifier));
      }

      File destFile = getDestFile();

      if (destFile.getParentFile() != null) {
        destFile.getParentFile().mkdirs();
      }

      if (mainclass == null) {
        String mc = build.getConfig().getProjectConfig().getMainclass();
        if (!StringUtils.isEmpty(mc)) {
          createMainclass().setName(mc);
        }
      }

      addMain(main);
    }

    if (mainclass != null) {
      String mc = mainclass.getName().replace('/', '.');
      if (mc.endsWith(".class")) {
        mc = mc.substring(0, mc.length() - ".class".length());
      }
      setOneJarMainClass(mc);
      manifestSet = true;
    }

    for (ZipDependencies deps : dependencies) {
      for (File jar : build.getSolver().getClasspath(deps.getScope(), deps.getTag())) {
        ZipFileSet fs = new ZipFileSet();
        fs.setProject(getProject());
        if (!StringUtils.isEmpty(deps.getPrefix())) {
          throw new MoxieException("Can not specify custom dependencies prefix for mx:onejar!");
        }
        fs.setPrefix("lib/");
        fs.setDir(jar.getParentFile());
        fs.setIncludes(jar.getName());
        addZipfileset(fs);
      }
    }

    if (isShowTitle()) {
      console.title(getClass(), getDestFile().getName());
    }

    long start = System.currentTimeMillis();

    super.execute();

    console.log(1, "{0} KB, generated in {1} ms", (getDestFile().length()/1024), System.currentTimeMillis() - start);

    /*
     * Build sources jar
     */
    if (packageSources) {
      String name = getDestFile().getName();
      if (!StringUtils.isEmpty(classifier)) {
        // replace the classifier with "sources"
        name = name.replace(classifier, "sources");
      } else {
        // append -sources to the filename before the extension
        name = name.substring(0, name.lastIndexOf('.')) + "-sources" + name.substring(name.lastIndexOf('.'));
      }
      File sourcesFile = new File(getDestFile().getParentFile(), name);
      if (sourcesFile.exists()) {
        sourcesFile.delete();
      }

      Jar jar = new Jar();
      jar.setTaskName(getTaskName());
      jar.setProject(getProject());

      // set the destination file
      jar.setDestFile(sourcesFile);

      List<File> folders = build.getConfig().getSourceDirectories(Scope.compile, tag);
      for (File folder : folders) {
        FileSet srcSet = new FileSet();
        srcSet.setProject(getProject());
        srcSet.setDir(folder);
        srcSet.setIncludes("**/*.java");
        jar.addFileset(srcSet);

        // include source folder resources
        FileSet resSet = new FileSet();
        resSet.setProject(getProject());
        resSet.setDir(folder);
        resSet.setExcludes(excludes);
        jar.addFileset(resSet);
      }

      if (includeResources) {
        for (File dir : build.getConfig().getResourceDirectories(Scope.compile, tag)) {
          FileSet set = new FileSet();
          set.setDir(dir);
          set.setExcludes(Toolkit.DEFAULT_RESOURCE_EXCLUDES);
          jar.addFileset(set);
        }
View Full Code Here



  @SuppressWarnings("unchecked")
  @Override
  public void execute() throws BuildException {
    Build build = getBuild();
    if (build != null) {
      // already initialized
      return;
    }
   
    if (mxroot != null && !mxroot.toString().startsWith("${")) {
      // MX_ROOT set by attribute
      Toolkit.setMxRoot(mxroot);
    }

    // load all environment variables into env property
        Map<String, String> osEnv = Execute.getEnvironmentVariables();
        for (Map.Entry<String, String> entry : osEnv.entrySet()) {
            getProject().setProperty("env." + entry.getKey(), entry.getValue());
        }
   
    // push all mx properties from ant into system
        // create properties map - this is written to work on Ant 1.8 and 1.9
    Map<String, String> antProperties = new HashMap<String, String>();
    for (Map.Entry<String, Object> entry : (Iterable<Map.Entry<String, Object>>) getProject().getProperties().entrySet()) {
      if (entry.getKey().startsWith("mx.")) {
        System.setProperty(entry.getKey(), entry.getValue().toString());
      }
      antProperties.put(entry.getKey(), entry.getValue().toString());
    }
   
    try {
      if (basedir == null) {
        basedir = getProject().getBaseDir();
      }

      File configFile;
      if (StringUtils.isEmpty(config)) {
        // default configuration       
        configFile = new File(basedir, "build.moxie");
      } else {
        // specified configuration
        FileUtils futils = FileUtils.getFileUtils();       
        configFile = futils.resolveFile(basedir, config);
      }
     
      if (!configFile.exists()) {
        throw new MoxieException(MessageFormat.format("Failed to find Moxie descriptor {0}", configFile));
      }
     
      // parse the config files and Moxie settings
      build = new Build(configFile, basedir);
     
      BuildConfig buildConfig = build.getConfig();
      buildConfig.setVerbose(isVerbose());
     
      // set any external properties into the project
      for (Map.Entry<String, String> entry : buildConfig.getExternalProperties().entrySet()) {
        getConsole().debug("setting external property {0} = {1}", entry.getKey(), entry.getValue());
        getProject().setProperty(entry.getKey(), entry.getValue());
      }
     
      build.getPom().setAntProperties(antProperties);     

      // add a reference to the full build object
      getProject().addReference(Key.build.referenceId(), build);     

      // output the build info
      build.describe();
     
      build.setup();
     
      if (isVerbose()) {
        getConsole().separator();
        getConsole().log(getProject().getProperty("ant.version"));
        getConsole().log("Moxie Build Toolkit version " + Toolkit.getVersion() + " compiled on " + Toolkit.getBuildDate());
      }

      Pom pom = build.getPom();
     
      // push all pom properties into project
      Map<String,String> properties = pom.getProperties();
      for (Map.Entry<String, String> entry : properties.entrySet()) {
        getProject().setProperty(entry.getKey(), entry.getValue());
      }

      if (isVerbose()) {
        getConsole().separator();
        getConsole().log("project properties");
      }
     
      setProjectProperty(Key.name, pom.name);
      setProjectProperty(Key.description, pom.description);
      setProjectProperty(Key.groupId, pom.groupId);
      setProjectProperty(Key.artifactId, pom.artifactId);
      setProjectProperty(Key.version, pom.version);
      setProjectProperty(Key.organization, pom.organization);
      setProjectProperty(Key.organizationUrl, pom.organizationUrl);
      setProjectProperty(Key.issuesUrl, pom.issuesUrl);
      setProjectProperty(Key.forumUrl, pom.forumUrl);
      setProjectProperty(Key.socialNetworkUrl, pom.socialNetworkUrl);
      setProjectProperty(Key.blogUrl, pom.blogUrl);
      setProjectProperty(Key.ciUrl, pom.ciUrl);
      setProjectProperty(Key.mavenUrl, pom.mavenUrl);
      setProjectProperty(Key.url, pom.url);
      if (pom.scm != null) {
        setProjectProperty(Key.scmUrl, pom.scm.url);
      }
      setProjectProperty(Key.mainclass, buildConfig.getProjectConfig().getMainclass());
      setProjectProperty(Key.releaseVersion, buildConfig.getPom().releaseVersion);
      setProjectProperty(Key.releaseDate, build.getReleaseDateString());
      setProjectProperty(Key.buildDate, build.getBuildDateString());
      setProjectProperty(Key.buildTimestamp, build.getBuildTimestamp());

      setReference(Key.buildDate, build.getBuildDate());
      setReference(Key.releaseDate, build.getReleaseDate());

      setProjectProperty(Key.outputDirectory, buildConfig.getOutputDirectory(null).toString());
      setProjectProperty(Key.compileOutputDirectory, buildConfig.getOutputDirectory(Scope.compile).toString());
      setProjectProperty(Key.testOutputDirectory, buildConfig.getOutputDirectory(Scope.test).toString());
View Full Code Here

    if (destinationDirectory == null) {
      throw new MoxieException("Destination directory must be set!");
    }

    Build build = getBuild();
    titleClass();

    List<Dependency> dependencies = new ArrayList<Dependency>();
    for (ScopedDependency dep : deps) {
      dependencies.add(dep.dependency);     
    }

    List<File> artifacts = build.getSolver().solve(scope,
        dependencies.toArray(new Dependency[dependencies.size()]));

    if (artifacts.size() > 0) {
      getConsole().log(1, "copying {0} artifacts => {1}", artifacts.size(), destinationDirectory);
      try {
View Full Code Here

  }

  @Override
  public void setProject(Project project) {
    super.setProject(project);
    Build build = (Build) getProject().getReference(Key.build.referenceId());
    if (build != null) {
      configure(build);
    }
  }
View Full Code Here

    }
  }

  @Override
  public void execute() {
    Build build = (Build) getProject().getReference(Key.build.referenceId());
    Console console = build.getConsole();

    if (!configured) {
      // called from moxie.compile
      configure(build);
    }

    if (scope == null) {
      scope = Scope.defaultScope;
    }

    if (builds == null) {
      // top-level mx:javac instantiates the build stack
      builds = new HashSet<Build>();
    }

    if (compileLinkedProjects) {
      for (Build linkedProject: build.getSolver().getLinkedModules()) {
        if (builds.contains(linkedProject)) {
          // already built, skip
          console.debug(1, "skipping {0}, already compiled", linkedProject.getPom().getManagementId());
          continue;
        }
        // add the build to the stack so we do not rebuild
        builds.add(linkedProject);

        try {
          // compile the linked project
          Project project = new Project();
          project.setBaseDir(linkedProject.getConfig().getProjectDirectory());
          project.addReference(Key.build.referenceId(), linkedProject);

          MxJavac subCompile = new MxJavac(builds);
          subCompile.setProject(project);
          subCompile.setShowtitle(false);
          subCompile.perform();
        } catch (Exception e) {
          console.error(e);
          throw new MoxieException(e);
        }
      }
    }

    if (isShowTitle()) {
      console.title(getClass(), build.getPom().getCoordinates() + ", " + scope.name());
    }

    console.debug("mxjavac configuration");

    // display specified mxjavac attributes
    MaxmlMap attributes = build.getConfig().getTaskAttributes(getTaskName());
    AttributeReflector.logAttributes(this, attributes, console);

    // project folder
    console.debug(1, "projectdir = {0}", build.getConfig().getProjectDirectory());

    // create sourcepath
    Path sources = createSrc();
    for (File file : build.getConfig().getSourceDirectories(scope, tag)) {
      PathElement element = sources.createPathElement();
      element.setLocation(file);
    }
    console.debug(1, "sources = {0}", sources);

    // set output folder
    setDestdir(build.getConfig().getOutputDirectory(scope));
    console.debug(1, "destdir = {0}", getDestdir());

    // create classpath
    Path classpath = createClasspath();
    if (Scope.test.equals(scope)) {
      // add the compile output folder
      PathElement element = classpath.createPathElement();
      element.setLocation(build.getConfig().getOutputDirectory(Scope.compile));
    }
    for (File file : build.getSolver().getClasspath(scope)) {
      PathElement element = classpath.createPathElement();
      element.setLocation(file);
    }
    for (Build subbuild : build.getSolver().getLinkedModules()) {
      PathElement element = classpath.createPathElement();
      element.setLocation(subbuild.getConfig().getOutputDirectory(Scope.compile));
    }
    console.debug(1, "classpath = {0}", classpath);

    for (SourceDirectory sd : build.getConfig().getSourceDirectories()) {
      // clean apt source directories before compiling
      if (sd.apt) {
        console.log("Cleaning apt source directory {0}", sd.name);
        FileUtils.delete(sd.getSources());
        sd.getSources().mkdirs();
      }
    }

    if (clean) {
      // clean the output folder before compiling
      console.log("Cleaning output directory {0}", getDestdir().getAbsolutePath());
      FileUtils.delete(getDestdir());
    }

    getDestdir().mkdirs();

    // set the update property name so we know if nothing compiled
    String prop = build.getPom().getCoordinates().replace(':', '.') + ".compiled";
    setUpdatedProperty(prop);
    super.execute();
    if (getProject().getProperty(prop) == null) {
      console.log(1, "compiled classes are up-to-date");
    }
View Full Code Here

    createReplace().set("${" + token + "}", value);
  }

  @Override
  public void execute() throws BuildException {
    Build build = getBuild();
   
    // automatically setup substitution tokens
    setToken(Toolkit.Key.name.projectId(), build.getPom().name);
    setToken(Toolkit.Key.description.projectId(), build.getPom().description);
    setToken(Toolkit.Key.url.projectId(), build.getPom().url);
    setToken(Toolkit.Key.issuesUrl.projectId(), build.getPom().issuesUrl);
    setToken(Toolkit.Key.inceptionYear.projectId(), build.getPom().inceptionYear);
    setToken(Toolkit.Key.organization.projectId(), build.getPom().organization);
    setToken(Toolkit.Key.organizationUrl.projectId(), build.getPom().organizationUrl);
    setToken(Toolkit.Key.forumUrl.projectId(), build.getPom().forumUrl);
    setToken(Toolkit.Key.socialNetworkUrl.projectId(), build.getPom().socialNetworkUrl);
    setToken(Toolkit.Key.blogUrl.projectId(), build.getPom().blogUrl);
    setToken(Toolkit.Key.ciUrl.projectId(), build.getPom().ciUrl);
    setToken(Toolkit.Key.mavenUrl.projectId(), build.getPom().mavenUrl);
    if (build.getPom().scm != null) {
      setToken(Key.scmUrl.projectId(), build.getPom().scm.url);
    }

    setToken(Toolkit.Key.groupId.projectId(), build.getPom().groupId);
    setToken(Toolkit.Key.artifactId.projectId(), build.getPom().artifactId);
    setToken(Toolkit.Key.version.projectId(), build.getPom().version);
    setToken(Toolkit.Key.coordinates.projectId(), build.getPom().getCoordinates());
   
    setToken(Toolkit.Key.buildDate.projectId(), build.getBuildDateString());
    setToken(Toolkit.Key.buildTimestamp.projectId(), build.getBuildTimestamp());
   
    setToken(Toolkit.Key.releaseVersion.projectId(), build.getPom().releaseVersion);
    setToken(Toolkit.Key.releaseDate.projectId(), build.getReleaseDateString());

    setToken(Toolkit.Key.releaseDate.referenceId(), build.getReleaseDate());
    setToken(Toolkit.Key.buildDate.referenceId(), build.getBuildDate());

    for (Map.Entry<String, String> entry : build.getPom().getProperties().entrySet()) {
      setToken(entry.getKey(), entry.getValue());
    }
   
    if (doc.name == null) {
      doc.name = build.getPom().name;
    }
   
    if (doc.sourceDirectory == null) {
      doc.sourceDirectory = build.getConfig().getSiteSourceDirectory();
    }

    if (doc.outputDirectory == null) {
      doc.outputDirectory = build.getConfig().getSiteTargetDirectory();
    }
   
    if (doc.templateDirectory == null) {
      doc.templateDirectory = new File(build.getConfig().getSiteSourceDirectory(), "templates");
    }
   
    doc.customLessFile = findFile(customLessFile);
    if (logo != null) {
      doc.logo = findFile(logo.getFile());
    }
    if (favicon != null) {
      doc.favicon = findFile(favicon.getFile());
    }
   
    titleClass(build.getPom().name);

    loadRuntimeDependencies(build,
        new Dependency("mx:pegdown"),
        new Dependency("mx:wikitext-core"),
        new Dependency("mx:wikitext-twiki"),
        new Dependency("mx:wikitext-textile"),
        new Dependency("mx:wikitext-tracwiki"),
        new Dependency("mx:wikitext-mediawiki"),
        new Dependency("mx:wikitext-confluence"),
        new Dependency("mx:freemarker"));

    Dependency bootstrap = new Dependency("mx:bootstrap");
    Dependency jquery = new Dependency("mx:jquery");
    Dependency d3js = new Dependency("mx:d3js");
    Dependency prettify = new Dependency("mx:prettify");
    Dependency less = new Dependency("mx:lesscss-engine");
   
    loadRuntimeDependencies(build, bootstrap, jquery, d3js, prettify, less);

    if (doc.outputDirectory.exists()) {
      FileUtils.delete(doc.outputDirectory);
    }
    doc.outputDirectory.mkdirs();
   
    if (doc.logo != null && doc.logo.exists()) {
      try {
        FileUtils.copy(doc.outputDirectory, doc.logo);
      } catch (IOException e) {
        getConsole().error(e, "Failed to copy logo file!");
      }
    }
   
    if (doc.favicon != null && doc.favicon.exists()) {
      try {
        FileUtils.copy(doc.outputDirectory, doc.favicon);
      } catch (IOException e) {
        getConsole().error(e, "Failed to copy favicon file!");
      }
    }
   
    extractBootstrap(bootstrap, less, doc.outputDirectory);
    extractJQuery(jquery, doc.outputDirectory);
    extractD3js(d3js, doc.outputDirectory);
    extractPrettify(prettify, doc.outputDirectory);
   
    // setup prev/next pager links
    preparePages(doc.structure.elements);
   
    for (DocPage page : doc.freeformPages) {
      // process out-of-structure template pages
      prepareTemplatePage(page);
    }
   
    // block directives
    createNomarkdown().configure("---NOMARKDOWN---", false, false);
    createNomarkdown().configure("---ESCAPE---", true, false);
    createNomarkdown().configure("---FIXED---", true, true);
    createNomarkdown().configure("```", true, true);
    doc.nomarkdowns.add(new ExcludeText("---EXCLUDE---"));
   
    // wikitext transform directives
    createWikiText().configureSyntax(Syntax.TWIKI);
    createWikiText().configureSyntax(Syntax.TEXTILE);
    createWikiText().configureSyntax(Syntax.TRACWIKI);
    createWikiText().configureSyntax(Syntax.MEDIAWIKI);
    createWikiText().configureSyntax(Syntax.CONFLUENCE);
   
    // language syntax highlighting directives
    createNomarkdown().configureLanguage("---CODE---", null);
    createNomarkdown().configureLanguage("---CSS---", "lang-css");
    createNomarkdown().configureLanguage("---JAVA---", "lang-java");
    createNomarkdown().configureLanguage("---JSON---", "lang-json");
    createNomarkdown().configureLanguage("---SQL---", "lang-sql");
    createNomarkdown().configureLanguage("---WIKI---", "lang-wiki");
    createNomarkdown().configureLanguage("---XML---", "lang-xml");
    createNomarkdown().configureLanguage("---YAML---", "lang-yaml");

    Docs.execute(build, doc, isVerbose());
   
    writeDependenciesAsJson();
   
    // add site resource directories
    for (File dir : build.getConfig().getResourceDirectories(Scope.site)) {
      createResource().createFileset().setDir(dir);
    }

    for (org.moxie.Resource resource : resources) {
      File destdir = doc.outputDirectory;
View Full Code Here

    if (doc.customLessFile != null && doc.customLessFile.exists()) {
      content += "\n" + FileUtils.readContent(doc.customLessFile, "\n");
    }
    FileUtils.writeContent(bsLess, content);

    Build build = getBuild();   
    loadRuntimeDependencies(build, new Dependency("mx:rhino"));

    // compile Bootstrap and custom.less overrides into css
    try {
      File bsCss = new File(outputFolder, "bootstrap/css/bootstrap.css");
View Full Code Here

    }
    return policy;
  }

  public void execute() {
    Build build = getBuild();
   
    Pom pom = build.getPom(tags);
   
    if (!StringUtils.isEmpty(name)) {
      pom.name = name;
    }
    if (!StringUtils.isEmpty(description)) {
      pom.description = description;
    }
    if (!StringUtils.isEmpty(artifactId)) {
      pom.artifactId = artifactId;
    }
   
    if (!allowSnapshots && pom.isSnapshot()) {
      // do not deploy snapshots into the repository
      return;
    }
   
    Dependency asDependency = new Dependency(pom.getCoordinates());
    IMavenCache artifactCache = getArtifactCache(pom.isSnapshot());
    File cacheRoot = artifactCache.getRootFolder();
    File artifactFile = artifactCache.getArtifact(asDependency, asDependency.extension);
    File artifactDir = artifactFile.getParentFile();
    File sourceDir = build.getConfig().getTargetDirectory();
   
    titleClass(pom.artifactId + "-" + pom.version);

    if (asDependency.isSnapshot()) {
      deploySnapshot(pom, sourceDir, artifactDir, artifactCache);
View Full Code Here

    /*
     * Prepare all variables and state.
     */
   
    Build build = getBuild();
    BuildConfig config = build.getConfig();
   
    // generate unit test info into build/tests
    unitTestOutputDirectory = new File(config.getOutputDirectory(null), "tests");
    FileUtils.delete(unitTestOutputDirectory);
    unitTestOutputDirectory.mkdirs();

    // generate unit test info into target/tests
    testReports = new File(config.getReportsTargetDirectory(), "tests");
    FileUtils.delete(testReports);
    testReports.mkdirs();
   
    // instrument classes for code coverages into build/instrumented-classes
    instrumentedBuild = new File(config.getOutputDirectory(null), "instrumented-classes");
    FileUtils.delete(instrumentedBuild);
    instrumentedBuild.mkdirs();

    // generate code coverage report into target/coverage
    coverageReports = new File(config.getReportsTargetDirectory(), "coverage");
    FileUtils.delete(coverageReports);
    coverageReports.mkdirs();

    // delete Corbertura metadata
    coberturaData = new File(config.getOutputDirectory(null), "cobertura.ser");
    coberturaData.delete();

    // delete EMMA metadata
    emmaData = new File(config.getOutputDirectory(null), "metadata.emma");
    emmaData.delete();

    // delete JaCoCo metadata
    jacocoData = new File(config.getOutputDirectory(null), "jacoco.exec");
    jacocoData.delete();

    classesDirectory = config.getOutputDirectory(Scope.compile);
    testClassesDirectory = config.getOutputDirectory(Scope.test);

    // define the test class fileset
    unitTests = new FileSet();
    unitTests.setProject(getProject());
    unitTests.setDir(testClassesDirectory);

    MaxmlMap attributes = config.getTaskAttributes(getTaskName());
    failureProperty = attributes.getString("failureProperty", "unit.test.failed");
    failOnError = attributes.getBoolean("failOnError", false);
    unitTests.createInclude().setName(attributes.getString("include", "**/*Test.class"));

    // classpath for tests
    // instrumented classes, unit test classes, and unit test libraries
    unitTestClasspath = new Path(getProject());
    unitTestClasspath.createPathElement().setPath(instrumentedBuild.getAbsolutePath());
    unitTestClasspath.createPath().setRefid(new Reference(getProject(), Key.testClasspath.referenceId()));
    unitTestClasspath.createPath().setRefid(new Reference(getProject(), Key.buildClasspath.referenceId()));
    unitTestClasspath.createPathElement().setPath(testClassesDirectory.getAbsolutePath());
   
    // log the unit test classpath to the console in debug mode   
    build.getConsole().debug("unit test classpath");
    for (String element : unitTestClasspath.toString().split(File.pathSeparator)) {
      build.getConsole().debug(1, element);
    }

    /*
     * Do the work.
     */
   
    // compile the code and unit test classes
    MxJavac compile = new MxJavac();
    compile.setProject(getProject());
    compile.setScope(Scope.test.name());
    compile.execute();

    // instrument code classes
    if (hasClass("net.sourceforge.cobertura.ant.InstrumentTask")) {     
      Cobertura.instrument(this);
    } else if (hasClass("com.vladium.emma.emmaTask")) {
      Emma.instrument(this);
    } else if (hasClass("org.jacoco.ant.AbstractCoverageTask")) {
      // jacoco wraps unit test tasks
    } else {
      build.getConsole().warn("SKIPPING code-coverage!");
      build.getConsole().warn("add \"- build jacoco\", \"- build cobertura\", or \"- build emma\" to your dependencies for code-coverage.");
    }
   
    // optional jvmarg for running unit tests
    String jvmarg = null;
    if (hasClass("org.jacoco.ant.AbstractCoverageTask")) {
      jvmarg = Jacoco.newJvmarg(this);
    }
   
    // execute unit tests
    if (hasClass("org.testng.TestNGAntTask")) { 
      TestNG.test(this, jvmarg);
    } else if (hasClass("junit.framework.Test")) {
      JUnit.test(this, jvmarg);
    } else {
      build.getConsole().warn("SKIPPING unit tests!");
      build.getConsole().warn("add \"- test junit\" or \"- test testng\" to your dependencies to execute unit tests.");
    }
   
    // generate code coverage reports
    if (hasClass("net.sourceforge.cobertura.ant.ReportTask")) {
      Cobertura.report(this);
    } else if (hasClass("com.vladium.emma.report.reportTask")) {
      Emma.report(this);
    } else if (hasClass("org.jacoco.ant.ReportTask")) {
      Jacoco.report(this);
    }
   
    if ((getProject().getProperty(getFailureProperty()) != null) && failOnError) {
      throw new MoxieException("{0} has failed unit tests! Build aborted!", build.getPom().getArtifactId());
    }
  }
View Full Code Here

 
  public void setRedirect(boolean value) {
    if (value) {
      redirectorElement = new RedirectorElement();
      redirectorElement.setProject(getProject());
      Build build = (Build) getProject().getReference(Key.build.referenceId());
      redirectorElement.setOutput(new File(build.getConfig().getOutputDirectory(null), "javadoc.log"));
      redirectorElement.setAppend(false);
    }
  }
View Full Code Here

TOP

Related Classes of org.moxie.Build

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.