Esempio n. 1
0
  /** Generate output JAR-file and packages */
  public void outputToJar() throws IOException {
    // create the manifest
    final Manifest manifest = new Manifest();
    final java.util.jar.Attributes atrs = manifest.getMainAttributes();
    atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.2");

    final Map map = manifest.getEntries();
    // create manifest
    Enumeration classes = _bcelClasses.elements();
    final String now = (new Date()).toString();
    final java.util.jar.Attributes.Name dateAttr = new java.util.jar.Attributes.Name("Date");
    while (classes.hasMoreElements()) {
      final JavaClass clazz = (JavaClass) classes.nextElement();
      final String className = clazz.getClassName().replace('.', '/');
      final java.util.jar.Attributes attr = new java.util.jar.Attributes();
      attr.put(dateAttr, now);
      map.put(className + ".class", attr);
    }

    final File jarFile = new File(_destDir, _jarFileName);
    final JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest);
    classes = _bcelClasses.elements();
    while (classes.hasMoreElements()) {
      final JavaClass clazz = (JavaClass) classes.nextElement();
      final String className = clazz.getClassName().replace('.', '/');
      jos.putNextEntry(new JarEntry(className + ".class"));
      final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
      clazz.dump(out); // dump() closes it's output stream
      out.writeTo(jos);
    }
    jos.close();
  }
Esempio n. 2
0
  /**
   * Extract the dependent libs and return the extracted jar files
   *
   * @return the collection of extracted files
   */
  private Collection<File> extractDependentLibs(final File cachedir) throws IOException {
    final Attributes attributes = getMainAttributes();
    if (null == attributes) {
      debug("no manifest attributes");
      return null;
    }

    final ArrayList<File> files = new ArrayList<File>();
    final String libs = attributes.getValue(RUNDECK_PLUGIN_LIBS);
    if (null != libs) {
      debug("jar libs listed: " + libs + " for file: " + pluginJar);
      if (!cachedir.isDirectory()) {
        if (!cachedir.mkdirs()) {
          debug("Failed to create cachedJar dir for dependent libs: " + cachedir);
        }
      }
      final String[] libsarr = libs.split(" ");
      extractJarContents(libsarr, cachedir);
      for (final String s : libsarr) {
        File libFile = new File(cachedir, s);
        libFile.deleteOnExit();
        files.add(libFile);
      }
    } else {
      debug("no jar libs listed in manifest: " + pluginJar);
    }
    return files;
  }
Esempio n. 3
0
  public void test_1562() throws Exception {
    Manifest man = new Manifest();
    Attributes att = man.getMainAttributes();
    att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");

    File outputZip = File.createTempFile("hyts_", ".zip");
    outputZip.deleteOnExit();
    ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(outputZip));
    File resources = Support_Resources.createTempFolder();

    for (String zipClass : new String[] {"Foo", "Bar"}) {
      zout.putNextEntry(new ZipEntry("foo/bar/execjartest/" + zipClass + ".class"));
      zout.write(getResource(resources, "hyts_" + zipClass + ".ser"));
    }

    zout.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
    man.write(zout);
    zout.close();

    // set up the VM parameters
    String[] args = new String[] {"-jar", outputZip.getAbsolutePath()};

    // execute the JAR and read the result
    String res = Support_Exec.execJava(args, null, false);

    assertTrue("Error executing ZIP : result returned was incorrect.", res.startsWith("FOOBAR"));
  }
Esempio n. 4
0
  // assuming that application was packaged according to the rules
  // we must have application jar, i.e. jar where we embed launcher
  // and have main application class listed as main class!
  // If there are more than one, or none - it will be treated as deployment error
  //
  // Note we look for both JavaFX executable jars and regular executable jars
  // As long as main "application" entry point is the same it is main class
  // (i.e. for FX jar we will use JavaFX manifest entry ...)
  public String getMainApplicationJar() {
    if (mainJar != null) {
      return mainJar;
    }

    if (appResources == null || applicationClass == null) {
      return null;
    }
    File srcdir = appResources.getBaseDirectory();
    for (String fname : appResources.getIncludedFiles()) {
      JarFile jf;
      try {
        jf = new JarFile(new File(srcdir, fname));
        Manifest m = jf.getManifest();
        Attributes attrs = (m != null) ? m.getMainAttributes() : null;
        if (attrs != null) {
          boolean javaMain = applicationClass.equals(attrs.getValue(Attributes.Name.MAIN_CLASS));
          boolean fxMain =
              applicationClass.equals(attrs.getValue(PackagerLib.MANIFEST_JAVAFX_MAIN));
          if (javaMain || fxMain) {
            useFXPackaging = fxMain;
            mainJar = fname;
            mainJarClassPath = attrs.getValue(Attributes.Name.CLASS_PATH);
            return mainJar;
          }
        }
      } catch (IOException ex) {
      }
    }
    return null;
  }
Esempio n. 5
0
 // TODO: includeRuntime should be not a flag but a path to runtime
 public static void writeToJar(
     ClassFileFactory factory,
     final OutputStream fos,
     @Nullable FqName mainClass,
     boolean includeRuntime) {
   try {
     Manifest manifest = new Manifest();
     final Attributes mainAttributes = manifest.getMainAttributes();
     mainAttributes.putValue("Manifest-Version", "1.0");
     mainAttributes.putValue("Created-By", "JetBrains Kotlin");
     if (mainClass != null) {
       mainAttributes.putValue("Main-Class", mainClass.getFqName());
     }
     JarOutputStream stream = new JarOutputStream(fos, manifest);
     for (String file : factory.files()) {
       stream.putNextEntry(new JarEntry(file));
       stream.write(factory.asBytes(file));
     }
     if (includeRuntime) {
       writeRuntimeToJar(stream);
     }
     stream.finish();
   } catch (IOException e) {
     throw new CompileEnvironmentException("Failed to generate jar file", e);
   }
 }
Esempio n. 6
0
  /**
   * tests case when Main-Class is not in the zip launched but in another zip referenced by
   * Class-Path
   *
   * @throws Exception in case of troubles
   */
  public void test_main_class_in_another_zip() throws Exception {
    File fooZip = File.createTempFile("hyts_", ".zip");
    File barZip = File.createTempFile("hyts_", ".zip");
    fooZip.deleteOnExit();
    barZip.deleteOnExit();

    // create the manifest
    Manifest man = new Manifest();
    Attributes att = man.getMainAttributes();
    att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
    att.put(Attributes.Name.CLASS_PATH, fooZip.getName());

    File resources = Support_Resources.createTempFolder();

    ZipOutputStream zoutFoo = new ZipOutputStream(new FileOutputStream(fooZip));
    zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class"));
    zoutFoo.write(getResource(resources, "hyts_Foo.ser"));
    zoutFoo.close();

    ZipOutputStream zoutBar = new ZipOutputStream(new FileOutputStream(barZip));
    zoutBar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
    man.write(zoutBar);

    zoutBar.putNextEntry(new ZipEntry("foo/bar/execjartest/Bar.class"));
    zoutBar.write(getResource(resources, "hyts_Bar.ser"));
    zoutBar.close();

    String[] args = new String[] {"-jar", barZip.getAbsolutePath()};

    // execute the JAR and read the result
    String res = Support_Exec.execJava(args, null, false);

    assertTrue("Error executing JAR : result returned was incorrect.", res.startsWith("FOOBAR"));
  }
Esempio n. 7
0
 /**
  * Returns the manifest of the jar which contains one of the specified extensions. The provided
  * ClassLoader is used for resource loading.
  *
  * @param cl A ClassLoader which should find the manifest.
  * @param extensions The values of many 'Extension-Name's jar-manifest attribute; used to identify
  *     the manifest. Matching is applied in decreasing order, i.e. first element is favored over
  *     the second, etc.
  * @return the requested manifest or null when not found.
  */
 public static Manifest getManifest(ClassLoader cl, String[] extensions) {
   final Manifest[] extManifests = new Manifest[extensions.length];
   try {
     Enumeration<URL> resources = cl.getResources("META-INF/MANIFEST.MF");
     while (resources.hasMoreElements()) {
       final InputStream is = resources.nextElement().openStream();
       final Manifest manifest;
       try {
         manifest = new Manifest(is);
       } finally {
         IOUtil.close(is, false);
       }
       Attributes attributes = manifest.getMainAttributes();
       if (attributes != null) {
         for (int i = 0; i < extensions.length && null == extManifests[i]; i++) {
           final String extension = extensions[i];
           if (extension.equals(attributes.getValue(Attributes.Name.EXTENSION_NAME))) {
             if (0 == i) {
               return manifest; // 1st one has highest prio - done
             }
             extManifests[i] = manifest;
           }
         }
       }
     }
   } catch (IOException ex) {
     throw new RuntimeException("Unable to read manifest.", ex);
   }
   for (int i = 1; i < extManifests.length; i++) {
     if (null != extManifests[i]) {
       return extManifests[i];
     }
   }
   return null;
 }
Esempio n. 8
0
 @Nullable
 public static String getMainClassName(URL url) throws IOException {
   @NotNull URL u = new URL("jar", "", url + "!/");
   @NotNull JarURLConnection uc = (JarURLConnection) u.openConnection();
   Attributes attr = uc.getMainAttributes();
   return (attr != null) ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
 }
Esempio n. 9
0
  /**
   * Writes out the attribute information of the specified manifest to the specified {@code
   * OutputStream}
   *
   * @param manifest the manifest to write out.
   * @param out The {@code OutputStream} to write to.
   * @throws IOException If an error occurs writing the {@code Manifest}.
   */
  static void write(Manifest manifest, OutputStream out) throws IOException {
    CharsetEncoder encoder = ThreadLocalCache.utf8Encoder.get();
    ByteBuffer buffer = ThreadLocalCache.byteBuffer.get();

    String version = manifest.mainAttributes.getValue(Attributes.Name.MANIFEST_VERSION);
    if (version != null) {
      writeEntry(out, Attributes.Name.MANIFEST_VERSION, version, encoder, buffer);
      Iterator<?> entries = manifest.mainAttributes.keySet().iterator();
      while (entries.hasNext()) {
        Attributes.Name name = (Attributes.Name) entries.next();
        if (!name.equals(Attributes.Name.MANIFEST_VERSION)) {
          writeEntry(out, name, manifest.mainAttributes.getValue(name), encoder, buffer);
        }
      }
    }
    out.write(LINE_SEPARATOR);
    Iterator<String> i = manifest.getEntries().keySet().iterator();
    while (i.hasNext()) {
      String key = i.next();
      writeEntry(out, NAME_ATTRIBUTE, key, encoder, buffer);
      Attributes attrib = manifest.entries.get(key);
      Iterator<?> entries = attrib.keySet().iterator();
      while (entries.hasNext()) {
        Attributes.Name name = (Attributes.Name) entries.next();
        writeEntry(out, name, attrib.getValue(name), encoder, buffer);
      }
      out.write(LINE_SEPARATOR);
    }
  }
Esempio n. 10
0
  /**
   * Display package name and version information for javax.mail.internet.
   *
   * <p>This example is a bit artificial, since examining the version of a jar from Sun Microsystems
   * is unusual.
   *
   * @return _more_
   * @throws IOException _more_
   */
  private static HashMap<String, String> getBuildInfo() throws IOException {
    GribVariableRenamer renamer = new GribVariableRenamer();
    HashMap<String, String> buildInfo = new HashMap<String, String>();

    Enumeration<URL> resources =
        renamer.getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
    while (resources.hasMoreElements()) {
      try {
        Manifest manifest = new Manifest(resources.nextElement().openStream());
        Attributes attrs = manifest.getMainAttributes();
        if (attrs != null) {
          String implTitle = attrs.getValue("Implementation-Title");
          if ((implTitle != null) && (implTitle.contains("ncIdv"))) {
            buildInfo.put("version", attrs.getValue("Implementation-Version"));
            String strDate = attrs.getValue("Built-On");

            CalendarDate cd = CalendarDate.parseISOformat(null, strDate);
            buildInfo.put("buildDate", cd.toString());

            break;
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return buildInfo;
  }
Esempio n. 11
0
  public static long oHpiVersionGet() {
    long vmajor = 0L;
    long vminor = 0L;
    long vaux = 0L;

    String sversion = null;
    try {
      // Trying to get version from jar manifest
      InputStream s = Hpi.class.getResourceAsStream("/META-INF/MANIFEST.MF");
      if (s != null) {
        Manifest m = new Manifest(s);
        Attributes a = m.getAttributes("org.openhpi");
        if (a != null) {
          sversion = a.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
        }
      }
    } catch (IOException e) {
      // do nothing
    }

    if (sversion != null) {
      String[] parts = sversion.split("\\.");
      if (parts.length >= 0) {
        vmajor = Long.parseLong(parts[0]);
      }
      if (parts.length >= 1) {
        vminor = Long.parseLong(parts[1]);
      }
      if (parts.length >= 2) {
        vaux = Long.parseLong(parts[2]);
      }
    }

    return (vmajor << 48) | (vminor << 32) | (vaux << 16);
  }
Esempio n. 12
0
  /** Jars a given directory or single file into a JarOutputStream. */
  public void jarDir(File dirOrFile2Jar, File destJar) throws IOException {

    if (dirOrFile2Jar == null || destJar == null) throw new IllegalArgumentException();

    mDestJarName = destJar.getCanonicalPath();
    FileOutputStream fout = new FileOutputStream(destJar);

    JarOutputStream jout;

    if (MAIN_CLASS != null) {
      Manifest manifest = new Manifest();
      Attributes attrs = manifest.getMainAttributes();
      attrs.putValue("Manifest-Version", "1.0");
      attrs.putValue("Class-Path", ".");
      attrs.putValue("Main-Class", MAIN_CLASS);
      /** Manifest-Version: 1.0 Class-Path: . Main-Class: test.JarTool */
      jout = new JarOutputStream(fout, manifest);
    } else {
      jout = new JarOutputStream(fout);
    }
    // jout.setLevel(0);
    try {
      jarDir(dirOrFile2Jar, jout, null);
    } catch (IOException ioe) {
      throw ioe;
    } finally {
      jout.close();
      fout.close();
    }
  }
  /**
   * Read the version information from a file with a given file name. The file must be a jar
   * manifest file and all its entries are searched for package names and their specification
   * version information. All information is collected in a map for later lookup of package names
   * and their versions.
   *
   * @param versionFileName name of the jar file containing version information
   */
  public static String readVersionFromFile(String applicationName, String versionFileName) {
    try {
      FileInputStream fileInput = new FileInputStream(versionFileName);
      Manifest manifest = new Manifest();
      manifest.read(fileInput);

      Map entries = manifest.getEntries();
      // Now write out the pre-entry attributes
      Iterator entryIterator = entries.entrySet().iterator();
      while (entryIterator.hasNext()) {
        Map.Entry currentEntry = (Map.Entry) entryIterator.next();
        String packageName = currentEntry.getKey().toString();
        packageName = normalizePackageName(packageName);
        Attributes attributes = (Attributes) currentEntry.getValue();
        String packageSpecVersion = attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
        packageSpecVersion = extractVersionInfo(packageSpecVersion);
        return packageSpecVersion;
      }
    } catch (IOException exception) {
      exception.printStackTrace();
    }

    // no version found
    return null;
  }
Esempio n. 14
0
  public static DocTranslet fromJarFile(File jarFile) throws DocTransletConfigurationException {

    try {
      JarFile inputJarFile = new JarFile(jarFile, false, JarFile.OPEN_READ);

      Manifest manifest = inputJarFile.getManifest();

      if (null == manifest) {

        throw new DocTransletConfigurationException(
            "Jar file '" + jarFile + "' doesn't contain a manifest.");
      }

      Attributes mainAttributes = manifest.getMainAttributes();

      String docTransletMainEntry = mainAttributes.getValue("doctranslet-main-entry");

      if (null == docTransletMainEntry) {

        throw new DocTransletConfigurationException(
            "Manifest in Jar file '"
                + jarFile
                + "' doesn't contain a doctranslet-main-entry specification.");
      }

      return new DocTranslet(docTransletMainEntry, new JarClassLoader(inputJarFile));
    } catch (IOException e) {
      throw new DocTransletConfigurationException(e);
    }
  }
Esempio n. 15
0
  /** Validate whether the jar file has a valid manifest, throw exception if invalid */
  static void validateJarManifest(final Attributes mainAttributes) throws InvalidManifestException {
    final String value1 = mainAttributes.getValue(RUNDECK_PLUGIN_ARCHIVE);
    final String plugvers = mainAttributes.getValue(RUNDECK_PLUGIN_VERSION);

    final String plugclassnames = mainAttributes.getValue(RUNDECK_PLUGIN_CLASSNAMES);
    if (null == value1) {
      throw new InvalidManifestException(
          "Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_ARCHIVE);
    } else if (!"true".equals(value1)) {
      throw new InvalidManifestException(RUNDECK_PLUGIN_ARCHIVE + " was not 'true': " + value1);
    }
    if (null == plugvers) {
      throw new InvalidManifestException(
          "Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_VERSION);
    }
    final VersionCompare pluginVersion = VersionCompare.forString(plugvers);
    if (!pluginVersion.atLeast(LOWEST_JAR_PLUGIN_VERSION)) {
      throw new InvalidManifestException(
          "Unsupported plugin version: " + RUNDECK_PLUGIN_VERSION + ": " + plugvers);
    }
    if (null == plugclassnames) {
      throw new InvalidManifestException(
          "Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_CLASSNAMES);
    }
  }
  public static void indexTargetPlatform(
      OutputStream outputStream,
      List<File> additionalJarFiles,
      long stopWaitTimeout,
      String... dirNames)
      throws Exception {

    Framework framework = null;

    Path tempPath = Files.createTempDirectory(null);

    ClassLoader classLoader = TargetPlatformIndexerUtil.class.getClassLoader();

    try (InputStream inputStream =
        classLoader.getResourceAsStream("META-INF/system.packages.extra.mf")) {

      Map<String, String> properties = new HashMap<>();

      properties.put(Constants.FRAMEWORK_STORAGE, tempPath.toString());

      Manifest extraPackagesManifest = new Manifest(inputStream);

      Attributes attributes = extraPackagesManifest.getMainAttributes();

      properties.put(
          Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, attributes.getValue("Export-Package"));

      ServiceLoader<FrameworkFactory> serviceLoader = ServiceLoader.load(FrameworkFactory.class);

      FrameworkFactory frameworkFactory = serviceLoader.iterator().next();

      framework = frameworkFactory.newFramework(properties);

      framework.init();

      BundleContext bundleContext = framework.getBundleContext();

      Bundle systemBundle = bundleContext.getBundle(0);

      TargetPlatformIndexer targetPlatformIndexer =
          new TargetPlatformIndexer(systemBundle, additionalJarFiles, dirNames);

      targetPlatformIndexer.index(outputStream);
    } finally {
      framework.stop();

      FrameworkEvent frameworkEvent = framework.waitForStop(stopWaitTimeout);

      if (frameworkEvent.getType() == FrameworkEvent.WAIT_TIMEDOUT) {
        throw new Exception(
            "OSGi framework event "
                + frameworkEvent
                + " triggered after a "
                + stopWaitTimeout
                + "ms timeout");
      }

      PathUtil.deltree(tempPath);
    }
  }
Esempio n. 17
0
  /**
   * フィルタ用の <code>Criteria</code> を構築します。
   *
   * @param crt
   * @param rundata
   * @param context
   * @return
   */
  @Override
  protected SelectQuery<TurbineUser> buildSelectQueryForFilter(
      SelectQuery<TurbineUser> query, RunData rundata, Context context) {
    // 指定部署IDの取得
    String filter = ALEipUtils.getTemp(rundata, context, LIST_FILTER_STR);
    String filter_role = ALEipUtils.getTemp(rundata, context, LIST_FILTER_ROLE_STR);

    // 指定部署が存在しているかを確認し、存在していなければ値を削除する
    Map<Integer, ALEipPost> gMap = ALEipManager.getInstance().getPostMap();
    if (filter != null
        && filter.trim().length() != 0
        && !gMap.containsKey(Integer.valueOf(filter))) {
      filter = null;
    }

    String filter_type = ALEipUtils.getTemp(rundata, context, LIST_FILTER_TYPE_STR);
    String crt_key = null;
    Attributes map = getColumnMap();
    if (filter == null || filter_type == null || filter.equals("")) {
      return query;
    }
    crt_key = map.getValue(filter_type);
    if (crt_key == null) {
      return query;
    }

    Expression exp = ExpressionFactory.matchDbExp(crt_key, filter);
    query.andQualifier(exp);

    currentPost = filter;
    currentRole = filter_role;
    return query;
  }
Esempio n. 18
0
  public static String getVersion(ServletContext application) {
    String defaultVersion = "";
    try {
      InputStream inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF");
      Manifest manifest = new Manifest(inputStream);
      Attributes attributes = manifest.getMainAttributes();
      String version = attributes.getValue("Application-Version");
      String builtTime = attributes.getValue("HudsonBuildId");
      String revision = attributes.getValue("HudsonBuildNumber");

      if (version != null
          && version != ""
          && builtTime != null
          && builtTime != ""
          && revision != null
          && revision != "") {

        String versionTmp = "";
        if (version.contains("SNAPSHOT")) {
          versionTmp = version.substring(0, version.indexOf("-"));
        } else {
          versionTmp = version;
        }

        return versionTmp + " Build " + builtTime.substring(0, 10) + " Rev:" + revision;
      }
    } catch (IOException e) {
    }
    return defaultVersion;
  }
Esempio n. 19
0
 @SuppressWarnings("resource")
 private InitStep loadInitStep(Path jar) {
   try {
     URLClassLoader pluginLoader =
         new URLClassLoader(
             new URL[] {jar.toUri().toURL()}, InitPluginStepsLoader.class.getClassLoader());
     try (JarFile jarFile = new JarFile(jar.toFile())) {
       Attributes jarFileAttributes = jarFile.getManifest().getMainAttributes();
       String initClassName = jarFileAttributes.getValue("Gerrit-InitStep");
       if (initClassName == null) {
         return null;
       }
       @SuppressWarnings("unchecked")
       Class<? extends InitStep> initStepClass =
           (Class<? extends InitStep>) pluginLoader.loadClass(initClassName);
       return getPluginInjector(jar).getInstance(initStepClass);
     } catch (ClassCastException e) {
       ui.message(
           "WARN: InitStep from plugin %s does not implement %s (Exception: %s)\n",
           jar.getFileName(), InitStep.class.getName(), e.getMessage());
       return null;
     } catch (NoClassDefFoundError e) {
       ui.message(
           "WARN: Failed to run InitStep from plugin %s (Missing class: %s)\n",
           jar.getFileName(), e.getMessage());
       return null;
     }
   } catch (Exception e) {
     ui.message(
         "WARN: Cannot load and get plugin init step for %s (Exception: %s)\n",
         jar, e.getMessage());
     return null;
   }
 }
Esempio n. 20
0
 public void start() {
   vlog.debug("start called");
   if (version == null || build == null) {
     ClassLoader cl = this.getClass().getClassLoader();
     InputStream stream = cl.getResourceAsStream("com/tigervnc/vncviewer/timestamp");
     try {
       Manifest manifest = new Manifest(stream);
       Attributes attributes = manifest.getMainAttributes();
       version = attributes.getValue("Version");
       build = attributes.getValue("Build");
     } catch (java.io.IOException e) {
     }
   }
   nViewers++;
   if (firstApplet) {
     alwaysShowServerDialog.setParam(true);
     Configuration.readAppletParams(this);
     String host = getCodeBase().getHost();
     if (vncServerName.getValue() == null && vncServerPort.getValue() != 0) {
       int port = vncServerPort.getValue();
       vncServerName.setParam(
           host + ((port >= 5900 && port <= 5999) ? (":" + (port - 5900)) : ("::" + port)));
     }
   }
   thread = new Thread(this);
   thread.start();
 }
Esempio n. 21
0
  /**
   * Gets the build teimstamp from the jar manifest
   *
   * @return build timestamp
   */
  private static String getManifestBuildTimestamp() {
    JarURLConnection connection = null;
    JarFile jarFile = null;
    URL url = Commons.class.getClassLoader().getResource("jaligner");
    try {
      // Get jar connection
      connection = (JarURLConnection) url.openConnection();

      // Get the jar file
      jarFile = connection.getJarFile();

      // Get the manifest
      Manifest manifest = jarFile.getManifest();

      // Get the manifest entries
      Attributes attributes = manifest.getMainAttributes();

      Attributes.Name name = new Attributes.Name(BUILD_TIMESTAMP);
      return attributes.getValue(name);
    } catch (Exception e) {
      String message = "Failed getting the current release info: " + e.getMessage();
      logger.log(Level.WARNING, message);
    }
    return null;
  }
Esempio n. 22
0
 static {
   final Enumeration<URL> resources;
   String jarName = "(unknown)";
   String versionString = "(unknown)";
   try {
     final ClassLoader classLoader = Main.class.getClassLoader();
     resources =
         classLoader == null
             ? ModuleClassLoader.getSystemResources("META-INF/MANIFEST.MF")
             : classLoader.getResources("META-INF/MANIFEST.MF");
     while (resources.hasMoreElements()) {
       final URL url = resources.nextElement();
       try {
         final InputStream stream = url.openStream();
         if (stream != null)
           try {
             final Manifest manifest = new Manifest(stream);
             final Attributes mainAttributes = manifest.getMainAttributes();
             if (mainAttributes != null
                 && "JBoss Modules".equals(mainAttributes.getValue("Specification-Title"))) {
               jarName = mainAttributes.getValue("Jar-Name");
               versionString = mainAttributes.getValue("Jar-Version");
             }
           } finally {
             StreamUtil.safeClose(stream);
           }
       } catch (IOException ignored) {
       }
     }
   } catch (IOException ignored) {
   }
   JAR_NAME = jarName;
   VERSION_STRING = versionString;
 }
Esempio n. 23
0
  @Override
  public String getVersion() {
    Class<BricketApplication> clazz = BricketApplication.class;
    String classPath = clazz.getResource(clazz.getSimpleName() + ".class").toString();
    if (!classPath.startsWith("jar")) {
      // class not from JAR
      return UNKNOWN_VERSION;
    }

    try {
      String manifestPath =
          classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
      Manifest manifest = new Manifest(new URL(manifestPath).openStream());
      Attributes attr = manifest.getMainAttributes();
      String version = attr.getValue(Name.IMPLEMENTATION_VERSION);
      return version != null ? version : UNKNOWN_VERSION;
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return UNKNOWN_VERSION;
  }
Esempio n. 24
0
 /** @tests java.util.jar.Attributes#isEmpty() */
 public void test_isEmpty() {
   assertTrue("Should not be empty", !a.isEmpty());
   a.clear();
   assertTrue("a) Should be empty", a.isEmpty());
   a = new Attributes();
   assertTrue("b) Should be empty", a.isEmpty());
 }
  private String getConfigInfoFromManifest(String configType, IPath portalDir) {
    File implJar = portalDir.append("/WEB-INF/lib/portal-impl.jar").toFile();

    String version = null;
    String serverInfo = null;

    if (implJar.exists()) {
      try (JarFile jar = new JarFile(implJar)) {
        Manifest manifest = jar.getManifest();

        Attributes attributes = manifest.getMainAttributes();

        version = attributes.getValue("Liferay-Portal-Version");
        serverInfo = attributes.getValue("Liferay-Portal-Server-Info");

        if (CoreUtil.compareVersions(Version.parseVersion(version), MANIFEST_VERSION_REQUIRED)
            < 0) {
          version = null;
          serverInfo = null;
        }
      } catch (IOException e) {
        LiferayServerCore.logError(e);
      }
    }

    if (configType.equals(CONFIG_TYPE_VERSION)) {
      return version;
    }

    if (configType.equals(CONFIG_TYPE_SERVER)) {
      return serverInfo;
    }

    return null;
  }
 private Manifest getManifest() throws IOException {
   Manifest manifest = new Manifest();
   Attributes a = manifest.getMainAttributes();
   a.put(Attributes.Name.MANIFEST_VERSION, "1.0"); // $NON-NLS-1$
   a.put(Attributes.Name.IMPLEMENTATION_VENDOR, "Talend Open Studio"); // $NON-NLS-1$
   a.put(Attributes.Name.CLASS_PATH, getClasspath());
   return manifest;
 }
Esempio n. 27
0
 /** @tests java.util.jar.Attributes#clear() */
 public void test_clear() {
   a.clear();
   assertNull("a) All entries should be null after clear", a.get("1"));
   assertNull("b) All entries should be null after clear", a.get("2"));
   assertNull("c) All entries should be null after clear", a.get("3"));
   assertNull("d) All entries should be null after clear", a.get("4"));
   assertTrue("Should not contain any keys", !a.containsKey("1"));
 }
Esempio n. 28
0
 @Override
 protected void setUp() {
   a = new Attributes();
   a.putValue("1", "one");
   a.putValue("2", "two");
   a.putValue("3", "three");
   a.putValue("4", "four");
 }
Esempio n. 29
0
 private Manifest getManifest() {
   Manifest manifest = new Manifest();
   Attributes a = new Attributes();
   a.put(Attributes.Name.IMPLEMENTATION_VERSION, "1.0"); // $NON-NLS-1$
   a.put(Attributes.Name.IMPLEMENTATION_VENDOR, "Talend Open Studio"); // $NON-NLS-1$
   manifest.getEntries().put(jarFile.getName(), a);
   return manifest;
 }
Esempio n. 30
0
 private static String loadManifestAttribute(final File file, final String attribute) {
   String value = null;
   final Attributes mainAttributes = loadMainAttributes(file);
   if (null != mainAttributes) {
     value = mainAttributes.getValue(attribute);
   }
   return value;
 }