Package org.apache.tools.ant.taskdefs

Examples of org.apache.tools.ant.taskdefs.Manifest


            InputStream is = OneJarTask.class.getResourceAsStream(ONE_JAR_BOOT);
            if (is == null)
                throw new IOException("Unable to load default " + ONE_JAR_BOOT + ": consider using the <one-jar onejarboot=\"...\"> option.");
            // Pull the manifest out and use it.
            JarInputStream jis = new JarInputStream(is);
            Manifest manifest = new Manifest();
            java.util.jar.Manifest jmanifest = jis.getManifest();
            java.util.jar.Attributes jattributes = jmanifest.getMainAttributes();
            try {
                // Specify our Created-By and Main-Class attributes as overrides.
              configureManifest(manifest);
                manifest.addConfiguredAttribute(new Attribute(MAIN_CLASS, jattributes.getValue(MAIN_CLASS)));
                if (oneJarMainClass != null) {
                    manifest.addConfiguredAttribute(new Attribute(Boot.ONE_JAR_MAIN_CLASS, oneJarMainClass));
                }
                super.addConfiguredManifest(manifest);
            } catch (ManifestException mx) {
                throw new BuildException(mx);
            }
View Full Code Here


      // called from moxie.package
      configure(build);
    }
   
    // automatic manifest entries from Moxie metadata
    Manifest manifest = new Manifest();
    configureManifest(manifest);

    if (mainclass == null) {
      String mc = build.getConfig().getProjectConfig().getMainclass();
      if (!StringUtils.isEmpty(mc)) {
        ClassSpec cs = new ClassSpec(getProject());
        mainclass = cs;
        mainclass.setName(mc);
      }
    }
   
    if (mainclass != null) {
      String mc = mainclass.getName().replace('/', '.');
      if (mc.endsWith(".class")) {
        mc = mc.substring(0, mc.length() - ".class".length());
      }
      if (launcher == null) {
        // use specified mainclass
        setManifest(manifest, "Main-Class", mc);
      } else {
        // inject Moxie Launcher class
        String mx = launcher.getName().replace('/', '.');
        if (mx.endsWith(".class")) {
          mx = mx.substring(0, mx.length() - ".class".length());
        }
        setManifest(manifest, "Main-Class", mx);
        setManifest(manifest, "mxMain-Class", mc);
        String paths = launcher.getPaths();
        if (!StringUtils.isEmpty(paths)) {
          setManifest(manifest, "mxMain-Paths", paths)
        }
      }
    }
    try {
      addConfiguredManifest(manifest);
    } catch (ManifestException e1) {
      console.error(e1, "Failed to configure manifest!");
      throw new MoxieException(e1);
    }
   
    if (fatjar) {
      // FatJar generation (merging reference dependencies)
      Object o = getProject().getReference(Key.runtimeClasspath.referenceId());
      if (o != null && o instanceof Path) {
        Path cp = (Path) o;
        for (String path : cp.list()) {
          if (path.toLowerCase().endsWith(".jar")) {
            ZipFileSet zip = new ZipFileSet();
            zip.setProject(getProject());
            if (!StringUtils.isEmpty(getClassFilesetPrefix())) {
              zip.setPrefix(getClassFilesetPrefix());
            }
            zip.setSrc(new File(path));
            zip.setExcludes("about.html, META-INF/*.DSA, META-INF/*.SF, META-INF/*.RSA, META-INF/LICENSE*, META-INF/NOTICE*, META-INF/ASL2.0, META-INF/eclipse.inf");
            addZipfileset(zip);
          }
        }
      }
    }
   
    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());
    if (!StringUtils.isEmpty(getClassFilesetPrefix())) {
      outputSet.setPrefix(getClassFilesetPrefix());
    }
    outputSet.setDir(outputFolder);
    if (includes != null) {
      outputSet.setIncludes(includes);
    }
    outputSet.setExcludes(excludes);   
    addFileset(outputSet);
   
    // add the output and resource folders of modules
    for (Build module : build.getSolver().getLinkedModules()) {
      ZipFileSet projectOutputSet = new ZipFileSet();
      projectOutputSet.setProject(getProject());
      if (!StringUtils.isEmpty(getClassFilesetPrefix())) {
        projectOutputSet.setPrefix(getClassFilesetPrefix());
      }
      File dir = module.getConfig().getOutputDirectory(Scope.compile);
      projectOutputSet.setDir(dir);
      if (includes != null) {
        projectOutputSet.setIncludes(includes);
      }
      projectOutputSet.setExcludes(excludes);   
      addFileset(projectOutputSet);
     
      if (includeResources) {
        // add linked module resources
        for (File resDir : module.getConfig().getResourceDirectories(Scope.compile)) {
          ZipFileSet resSet = new ZipFileSet();
          if (!StringUtils.isEmpty(resourceFolderPrefix)) {
              resSet.setPrefix(resourceFolderPrefix);
          }
          resSet.setProject(getProject());
          resSet.setDir(resDir);
          resSet.setExcludes(Toolkit.DEFAULT_RESOURCE_EXCLUDES);
          addFileset(resSet);
        }
      }
    }

    // resource directories
    if (includeResources) {
      for (File dir : build.getConfig().getResourceDirectories(Scope.compile, tag)) {
        ZipFileSet set = new ZipFileSet();
        if (!StringUtils.isEmpty(resourceFolderPrefix)) {
            set.setPrefix(resourceFolderPrefix);
        }
        set.setProject(getProject());
        set.setDir(dir);
        set.setExcludes(Toolkit.DEFAULT_RESOURCE_EXCLUDES);
        addFileset(set);
      }
    }
   
    if (getDestFile() == null) {
      setDestFile(build.getBuildArtifact(classifier));
    }
   
    File destFile = getDestFile();
   
    if (destFile.getParentFile() != null) {
      destFile.getParentFile().mkdirs();
    }
   
    addMavenEntries();
   
    if (isShowTitle()) {
      console.title(getClass(), destFile.getName());
    }
   
    console.debug(getTaskName() + " configuration");

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

    // optionally inject MxLauncher utility
    if (launcher != null) {
      if (launcher.getName().equals(MxLauncher.class.getName().replace('.', '/') + ".class")) {
        // inject MxLauncher into the output folder of the project
        for (String cn : Arrays.asList(MxLauncher.class.getName(), MxLauncher.class.getName() + "$1")) {           
          try {
            String fn = cn.replace('.', '/') + ".class";
            InputStream is = MxLauncher.class.getResourceAsStream("/" + fn);
            if (is == null) {
              continue;
            }
            build.getConsole().log("Injecting {0} into output folder", cn);
            File file = new File(outputFolder, fn.replace('/', File.separatorChar));
            if (file.exists()) {
              file.delete();
            }
            file.getParentFile().mkdirs();
            FileOutputStream os = new FileOutputStream(file, false);
            byte [] buffer = new byte[4096];
            int len = 0;
            while ((len = is.read(buffer)) > 0) {
              os.write(buffer,  0,  len);
            }
            is.close();
            os.flush();
            os.close();
          } catch (Exception e) {
            build.getConsole().error(e, "Failed to inject {0} into {1}",
                launcher.getName(), outputFolder);
          }
        }
      }
    }
   
    long start = System.currentTimeMillis();
    super.execute();

    if (fatjar) {
      // try to merge duplicate META-INF/services files
      JarUtils.mergeMetaInfServices(console, destFile);
    }
   
    console.log(1, "{0} KB, generated in {1} ms", (destFile.length()/1024), System.currentTimeMillis() - start);
   
    /*
     * Build sources jar
     */
    if (packageSources) {
      String name = destFile.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(destFile.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);
        }
      }
     
      // set the source jar manifest
      try {
        Manifest mft = new Manifest();
        configureManifest(mft);
        jar.addConfiguredManifest(mft);
      } catch (ManifestException e) {
        console.error(e);
      }
View Full Code Here

    }
  }
 
  void configureManifest(Manifest manifest) {
    // set manifest entries from Moxie metadata
    Manifest mft = new Manifest();
    setManifest(mft, "Created-By", "Moxie v" + Toolkit.getVersion());
    setManifest(mft, "Build-Jdk", System.getProperty("java.version"));
    setManifest(mft, "Build-Date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));

    setManifest(mft, "Implementation-Title", Key.name);
View Full Code Here

        }
      }

      // set the source jar manifest
      try {
        Manifest mft = new Manifest();
        configureManifest(mft);
        jar.addConfiguredManifest(mft);
      } catch (ManifestException e) {
        console.error(e);
      }
View Full Code Here

    }
  }
 
  void configureManifest(Manifest manifest) {
    // set manifest entries from Moxie metadata
    Manifest mft = new Manifest();
    setManifest(mft, "Created-By", "Moxie v" + Toolkit.getVersion());
    setManifest(mft, "Build-Jdk", System.getProperty("java.version"));
    setManifest(mft, "Build-Date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));

    setManifest(mft, "Implementation-Title", Key.name);
View Full Code Here

            InputStream is = OneJarTask.class.getResourceAsStream(ONE_JAR_BOOT);
            if (is == null)
                throw new IOException("Unable to load default " + ONE_JAR_BOOT + ": consider using the <one-jar onejarboot=\"...\"> option.");
            // Pull the manifest out and use it.
            JarInputStream jis = new JarInputStream(is);
            Manifest manifest = new Manifest();
            java.util.jar.Manifest jmanifest = jis.getManifest();
            java.util.jar.Attributes jattributes = jmanifest.getMainAttributes();
            try {
                // Specify our Created-By and Main-Class attributes as overrides.
                manifest.addConfiguredAttribute(new Attribute("Created-By", "One-Jar 0.98 Ant taskdef"));
                manifest.addConfiguredAttribute(new Attribute(MAIN_CLASS, jattributes.getValue(MAIN_CLASS)));
                if (oneJarMainClass != null) {
                    manifest.addConfiguredAttribute(new Attribute(Boot.ONE_JAR_MAIN_CLASS, oneJarMainClass));
                }
                super.addConfiguredManifest(manifest);
            } catch (ManifestException mx) {
                throw new BuildException(mx);
            }
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.taskdefs.Manifest

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.