/** @throws Exception If failed. */
  public void testAntGarTaskToString() throws Exception {
    String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir");
    String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir");
    String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_6";
    String metaDirName = baseDirName + File.separator + "META-INF";
    String garFileName = baseDirName + ".gar";

    // Make base and META-INF dir.
    boolean mkdir = new File(baseDirName).mkdirs();

    assert mkdir;

    mkdir = new File(metaDirName).mkdirs();

    assert mkdir;

    // Copy files to basedir
    U.copy(new File(srcDirName), new File(baseDirName), true);

    IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask();

    Project garProject = new Project();

    garProject.setName("Gar test project");

    garTask.setDestFile(new File(garFileName));
    garTask.setBasedir(new File(garFileName));
    garTask.setProject(garProject);
    garTask.setDescrdir(new File(garFileName));

    garTask.toString();
  }
 public final void setupTask(ModelGeneratorTask task) {
   File testDir = new File("build/test/generated");
   File backupDir = new File("build/test/backup");
   if (!testDir.exists()) {
     testDir.mkdirs();
   }
   if (!backupDir.exists()) {
     backupDir.mkdirs();
   }
   task.setDestDir(new File("build/test/generated"));
   task.setBackupDir(new File("build/test/backup"));
   Project project = new Project();
   project.setName("Test");
   task.setProject(project);
 }
  /** @throws Exception If failed. */
  @SuppressWarnings({"TypeMayBeWeakened"})
  public void testCorrectAntGarTask() throws Exception {
    String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir");
    String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir");
    String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_0";
    String metaDirName = baseDirName + File.separator + "META-INF";
    String garFileName = baseDirName + ".gar";
    String garDescDirName =
        U.resolveIgnitePath(GridTestProperties.getProperty("ant.gar.descriptor.dir"))
                .getAbsolutePath()
            + File.separator
            + "ignite.xml";

    // Make base and META-INF dir.
    boolean mkdir = new File(baseDirName).mkdirs();

    assert mkdir;

    mkdir = new File(metaDirName).mkdirs();

    assert mkdir;

    // Make Gar file
    U.copy(new File(garDescDirName), new File(metaDirName + File.separator + "ignite.xml"), true);

    // Copy files to basedir
    U.copy(new File(srcDirName), new File(baseDirName), true);

    IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask();

    Project garProject = new Project();

    garProject.setName("Gar test project");

    garTask.setDestFile(new File(garFileName));
    garTask.setBasedir(new File(baseDirName));
    garTask.setProject(garProject);

    garTask.execute();

    File garFile = new File(garFileName);

    assert garFile.exists();

    boolean res = checkStructure(garFile, true);

    assert res;
  }
  /** @throws Exception If failed. */
  public void testAntGarTaskWithDoubleP2PDescriptor() throws Exception {
    String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir");
    String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir");
    String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_2";
    String metaDirName = baseDirName + File.separator + "META-INF";
    String garFileName = baseDirName + ".gar";
    String garDescrDirName =
        U.resolveIgnitePath(GridTestProperties.getProperty("ant.gar.descriptor.dir"))
                .getAbsolutePath()
            + File.separator
            + "ignite.xml";

    // Make base and META-INF dir.
    boolean mkdir = new File(baseDirName).mkdirs();

    assert mkdir;

    mkdir = new File(metaDirName).mkdirs();

    assert mkdir;

    // Make Gar file
    U.copy(new File(garDescrDirName), new File(metaDirName + File.separator + "ignite.xml"), true);

    // Copy files to basedir
    U.copy(new File(srcDirName), new File(baseDirName), true);

    IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask();

    Project garProject = new Project();

    garProject.setName("Gar test project");

    garTask.setDestFile(new File(garFileName));
    garTask.setDescrdir(new File(garDescrDirName));
    garTask.setBasedir(new File(baseDirName));
    garTask.setProject(garProject);

    try {
      garTask.execute();

      assert false;
    } catch (BuildException e) {
      if (log().isInfoEnabled()) log().info(e.getMessage());
    }
  }
Exemplo n.º 5
0
 /**
  * Create ANT project that can be executed programatically
  *
  * @param scenariosPath
  * @param scenarioFile
  * @param sutFile
  * @return
  */
 private Project createNewAntProject(
     File scenariosPath, File scenarioFile, String scenarioName, String sutName) {
   System.setProperty(RunningProperties.CURRENT_SCENARIO_NAME, scenarioName);
   System.setProperty(RunningProperties.CURRENT_SUT, sutName);
   Project p = new Project();
   p.setName("JSystem Maven Plugin Project");
   p.setBaseDir(mavenProject.getBasedir());
   p.addBuildListener(new AntExecutionListener());
   p.setProperty("basedir", scenariosPath.getAbsolutePath());
   p.setProperty("scenarios.base", scenariosPath.getParentFile().getAbsolutePath());
   p.setProperty("sutFile", sutName);
   p.setProperty("ant.file", scenarioFile.getAbsolutePath());
   DefaultLogger consoleLogger = new DefaultLogger();
   consoleLogger.setErrorPrintStream(System.err);
   consoleLogger.setOutputPrintStream(System.out);
   consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
   p.addBuildListener(consoleLogger);
   return p;
 }
    /**
     * Initialisation routine called after handler creation with the element name and attributes.
     * The attributes which this handler can deal with are: <code>"default"</code>, <code>"name"
     * </code>, <code>"id"</code> and <code>"basedir"</code>.
     *
     * @param uri The namespace URI for this element.
     * @param tag Name of the element which caused this handler to be created. Should not be <code>
     *     null</code>. Ignored in this implementation.
     * @param qname The qualified name for this element.
     * @param attrs Attributes of the element which caused this handler to be created. Must not be
     *     <code>null</code>.
     * @param context The current context.
     * @exception SAXParseException if an unexpected attribute is encountered or if the <code>
     *     "default"</code> attribute is missing.
     */
    public void onStartElement(
        String uri, String tag, String qname, Attributes attrs, AntXMLContext context)
        throws SAXParseException {
      String baseDir = null;
      boolean nameAttributeSet = false;

      Project project = context.getProject();
      // Set the location of the implicit target associated with the project tag
      context.getImplicitTarget().setLocation(new Location(context.getLocator()));

      /**
       * XXX I really don't like this - the XML processor is still too 'involved' in the processing.
       * A better solution (IMO) would be to create UE for Project and Target too, and then process
       * the tree and have Project/Target deal with its attributes ( similar with Description ).
       *
       * <p>If we eventually switch to ( or add support for ) DOM, things will work smoothly - UE
       * can be avoided almost completely ( it could still be created on demand, for backward
       * compatibility )
       */
      for (int i = 0; i < attrs.getLength(); i++) {
        String attrUri = attrs.getURI(i);
        if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {
          continue; // Ignore attributes from unknown uris
        }
        String key = attrs.getLocalName(i);
        String value = attrs.getValue(i);

        if (key.equals("default")) {
          if (value != null && !value.equals("")) {
            if (!context.isIgnoringProjectTag()) {
              project.setDefault(value);
            }
          }
        } else if (key.equals("name")) {
          if (value != null) {
            context.setCurrentProjectName(value);
            nameAttributeSet = true;
            if (!context.isIgnoringProjectTag()) {
              project.setName(value);
              project.addReference(value, project);
            } else if (isInIncludeMode()) {
              if (!"".equals(value)
                  && (getCurrentTargetPrefix() == null || getCurrentTargetPrefix().length() == 0)) {
                // help nested include tasks
                setCurrentTargetPrefix(value);
              }
            }
          }
        } else if (key.equals("id")) {
          if (value != null) {
            // What's the difference between id and name ?
            if (!context.isIgnoringProjectTag()) {
              project.addReference(value, project);
            }
          }
        } else if (key.equals("basedir")) {
          if (!context.isIgnoringProjectTag()) {
            baseDir = value;
          }
        } else {
          // XXX ignore attributes in a different NS ( maybe store them ? )
          throw new SAXParseException(
              "Unexpected attribute \"" + attrs.getQName(i) + "\"", context.getLocator());
        }
      }

      // XXX Move to Project ( so it is shared by all helpers )
      String antFileProp = MagicNames.ANT_FILE + "." + context.getCurrentProjectName();
      String dup = project.getProperty(antFileProp);
      String typeProp = MagicNames.ANT_FILE_TYPE + "." + context.getCurrentProjectName();
      String dupType = project.getProperty(typeProp);
      if (dup != null && nameAttributeSet) {
        Object dupFile = null;
        Object contextFile = null;
        if (MagicNames.ANT_FILE_TYPE_URL.equals(dupType)) {
          try {
            dupFile = new URL(dup);
          } catch (java.net.MalformedURLException mue) {
            throw new BuildException(
                "failed to parse "
                    + dup
                    + " as URL while looking"
                    + " at a duplicate project"
                    + " name.",
                mue);
          }
          contextFile = context.getBuildFileURL();
        } else {
          dupFile = new File(dup);
          contextFile = context.getBuildFile();
        }

        if (context.isIgnoringProjectTag() && !dupFile.equals(contextFile)) {
          project.log(
              "Duplicated project name in import. Project "
                  + context.getCurrentProjectName()
                  + " defined first in "
                  + dup
                  + " and again in "
                  + contextFile,
              Project.MSG_WARN);
        }
      }
      if (nameAttributeSet) {
        if (context.getBuildFile() != null) {
          project.setUserProperty(antFileProp, context.getBuildFile().toString());
          project.setUserProperty(typeProp, MagicNames.ANT_FILE_TYPE_FILE);
        } else if (context.getBuildFileURL() != null) {
          project.setUserProperty(antFileProp, context.getBuildFileURL().toString());
          project.setUserProperty(typeProp, MagicNames.ANT_FILE_TYPE_URL);
        }
      }
      if (context.isIgnoringProjectTag()) {
        // no further processing
        return;
      }
      // set explicitly before starting ?
      if (project.getProperty("basedir") != null) {
        project.setBasedir(project.getProperty("basedir"));
      } else {
        // Default for baseDir is the location of the build file.
        if (baseDir == null) {
          project.setBasedir(context.getBuildFileParent().getAbsolutePath());
        } else {
          // check whether the user has specified an absolute path
          if ((new File(baseDir)).isAbsolute()) {
            project.setBasedir(baseDir);
          } else {
            project.setBaseDir(FILE_UTILS.resolveFile(context.getBuildFileParent(), baseDir));
          }
        }
      }
      project.addTarget("", context.getImplicitTarget());
      context.setCurrentTarget(context.getImplicitTarget());
    }
Exemplo n.º 7
0
  /**
   * This method will run client gen on the given WSDL.
   *
   * @throws MojoExecutionException Thrown if we fail to obtain the WSDL.
   */
  public void execute() throws MojoExecutionException {
    super.execute();

    if (getLog().isInfoEnabled()) {
      getLog().info("Weblogic client gen beginning ");
    }
    if (getLog().isInfoEnabled()) {
      getLog().info(" Detailed client gen settings information " + this.toString());
    }

    try {
      final ClientGenTask clientGen = new ClientGenTask();
      // Set the classpath
      final Project project = new Project();
      project.setName("clientgen");
      final Path path =
          new Path(
              project,
              WeblogicMojoUtilities.getDependencies(
                  this.getArtifacts(), this.getPluginArtifacts()));
      clientGen.setProject(project);
      clientGen.setClasspath(path);

      // in WebLogic 10.3 some methods were renamed (e.g. "setDestDir()") or removed (e.g.
      // "setOverwrite()")
      // so we have to use reflection here
      //            clientGen.setOverwrite( true );
      Method method = ReflectionUtils.getSetter("overwrite", clientGen.getClass());
      if (method != null) {
        method.invoke(clientGen, new Object[] {Boolean.TRUE});
      }
      //            clientGen.setDestdir( new File( this.outputDir ) );
      method = ReflectionUtils.getSetter("destdir", clientGen.getClass());
      if (method != null) {
        method.invoke(clientGen, new Object[] {new File(this.outputDir)});
      }
      //            clientGen.setDestDir( new File( this.outputDir ) );
      method = ReflectionUtils.getSetter("destDir", clientGen.getClass());
      if (method != null) {
        method.invoke(clientGen, new Object[] {new File(this.outputDir)});
      }

      clientGen.setVerbose(this.verbose);
      clientGen.setPackageName(this.packageName);
      clientGen.setIncludeGlobalTypes(this.useServerTypes);
      clientGen.setJaxRPCWrappedArrayStyle(this.jaxRPCWrappedArrayStyle);
      String wsdlUri;
      if (this.warFileName != null) {
        if (getLog().isInfoEnabled()) {
          getLog()
              .info(
                  " calculating wsdl URI from warFileName "
                      + this.warFileName
                      + " with wsdl "
                      + this.inputWSDL);
        }
        wsdlUri =
            "jar:file:"
                + WeblogicMojoUtilities.getWarFileName(this.getArtifacts(), this.warFileName)
                + "!"
                + this.inputWSDL;
        new File(this.inputWSDL).toURI().toString();
        if (getLog().isInfoEnabled()) {
          getLog().info(" using " + wsdlUri + " for clientgen.");
        }
      } else if (this.inputWSDL.startsWith("http")) {
        if (getLog().isInfoEnabled()) {
          getLog().info(" using " + this.inputWSDL + " for clientgen.");
        }
        wsdlUri = this.inputWSDL;
      } else {
        wsdlUri = new File(this.inputWSDL).toURI().toString();
        if (getLog().isInfoEnabled()) {
          getLog().info(" using " + wsdlUri + " for clientgen.");
        }
      }
      clientGen.setWsdl(wsdlUri);
      // set the service name if it is specified
      if (this.serviceName != null) {
        if (getLog().isInfoEnabled()) {
          getLog().info(" generating client for service '" + this.serviceName + "'.");
        }
        clientGen.setServiceName(this.serviceName);
      }
      clientGen.execute();
    } catch (Exception ex) {
      getLog().error("Exception encountered during client gen", ex);
      throw new MojoExecutionException("Exception encountered during listapps", ex);
    } finally {
      WeblogicMojoUtilities.unsetWeblogicProtocolHandler();
    }

    if (getLog().isInfoEnabled()) {
      getLog().info("Weblogic client gen successful ");
    }
  }