public String toString() {
   if (isInstantiated()) {
     return "{" + getValue() + "}";
   } else {
     return "{"
         + Helper.getShortClassName(getClass())
         + ": "
         + ToStringLocalization.buildMessage("not_instantiated", (Object[]) null)
         + "}";
   }
 }
  /**
   * INTERNAL: This method perform all necessary steps(verification, pre-build the target directory)
   * prior to the invocation of the weaving function.
   */
  private void preProcess() throws URISyntaxException, MalformedURLException {
    // Instantiate default session log
    AbstractSessionLog.getLog().setLevel(this.logLevel);
    if (logWriter != null) {
      ((DefaultSessionLog) AbstractSessionLog.getLog()).setWriter(logWriter);
    }

    // Make sure the source is existing
    if (!(new File(Helper.toURI(source)).exists())) {
      throw StaticWeaveException.missingSource();
    }

    URI targetURI = Helper.toURI(target);
    // Verification target and source, two use cases create warning or exception.
    // 1. If source is directory and target is jar -
    //   This will lead unknown outcome, user attempt to use this tool to pack outcome into a Jar.
    //   Warning message will be logged, this is can be worked around by other utilities.
    // 2. Both source and target are specified as a same jar -
    //   User was trying to perform weaving in same Jar which is not supported, an Exception will be
    // thrown.
    if (isDirectory(source) && targetURI.toString().endsWith(".jar")) {
      AbstractSessionLog.getLog()
          .log(
              SessionLog.WARNING,
              ToStringLocalization.buildMessage(
                  "staticweave_processor_unknown_outcome", new Object[] {null}));
    }

    if (!isDirectory(source) && target.toString().equals(source.toString())) {
      throw StaticWeaveException.weaveInplaceForJar(source.toString());
    }

    // pre-create target if it is directory and dose not exist.
    // Using the method File.isDirectory() is not enough to determine what the type(dir or jar)
    // of the target(specified by URL)that user want to create. File.isDirectory() will return false
    // in
    // two possibilities, the location either is not directory or the location dose not exist.
    // Therefore pre-build of the directory target is required. Pre-build for the file(JAR) target
    // is not required since it gets built automatically by opening outputstream.
    if (!(new File(targetURI)).exists()) {
      if (!targetURI.toString().endsWith(".jar")) {
        (new File(targetURI)).mkdirs();
        // if directory fails to build, which may leads to unknown outcome since it will
        // be treated as single file in the class StaticWeaveHandler and automatically gets built
        // by outputstream.

        // re-assign URL.
        target = (new File(targetURI)).toURL();
      }
    }
  }
Exemplo n.º 3
0
 /** Print the in progress depth. */
 public String toString() {
   Object[] args = {Integer.valueOf(this.commitDepth)};
   return Helper.getShortClassName(getClass())
       + ToStringLocalization.buildMessage("commit_depth", args);
 }