All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jfxtras.CreatePlaceholderPoms Maven / Gradle / Ivy

Go to download

This plugin offers a possibility to deploy the JavaFX SDK jars to your local repository.

The newest version!
/**
 * Copyright (c) 2008-2010, JFXtras Group
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. Neither the name of JFXtras nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

package org.jfxtras;

import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoExecutionException;
import org.sonatype.plexus.component.bundlepublisher.model.BundleArtifact;
import org.sonatype.plexus.component.bundlepublisher.model.BundleDescriptor;

import java.io.File;
import java.io.IOException;

/**
 * Creates placeholder poms that may be deployed to repositories without violating the JavaFX SDK license
 *
 * @author Johannes Schneider ([email protected])
 * @goal create-placeholder-poms
 */
public class CreatePlaceholderPoms extends AbstractJavaFxMojo {
  /**
   * Location of the output directory for the placeholder poms
   *
   * @parameter expression="${basedir}/target/javafx-placeholder-poms"
   */
  protected File outputDir;

  @Override
  protected void execute( File sdkInstallDir, BundleDescriptor descriptor, String version ) throws Exception {
    if ( outputDir == null ) {
      throw new MojoExecutionException( "output dir not set" );
    }
    outputDir.mkdirs();
    createPlaceholderPoms( sdkInstallDir, descriptor, version );
  }

  protected void createPlaceholderPoms( File sdkInstallDir, BundleDescriptor descriptor, String defaultVersion ) throws Exception {
    for ( BundleArtifact bundleArtifact : descriptor.getArtifacts() ) {
      File jar = new File( sdkInstallDir, bundleArtifact.getLocation() );
      if ( !jar.exists() ) {
        throw new MojoExecutionException( "File not found at <" + jar.getAbsolutePath() + ">" );
      }

      String groupId = bundleArtifact.getGroupId() != null ? bundleArtifact.getGroupId() : descriptor.getDefaults().getGroupId();
      String artifactId = bundleArtifact.getArtifactId();
      String version = bundleArtifact.getVersion() != null ? bundleArtifact.getVersion() : defaultVersion;

      Model model = createModel( groupId, artifactId, version );

      File pom = createPom( model );
      getLog().info( "Created pom @ " + pom.getAbsolutePath() );
    }
  }

  private File createPom( Model model ) throws IOException {
    File dir = createDir( model.getGroupId(), model.getArtifactId(), model.getVersion() );

    File file = new File( dir, model.getArtifactId() + "-" + model.getVersion() + ".pom" );
    writeModelToFile( model, file );
    return file;
  }

  private File createDir( String groupId, String artifactId, String version ) {
    String[] parts = groupId.split( "\\." );
    File current = outputDir;
    for ( String part : parts ) {
      current = new File( current, part );
    }
    current = new File( current, artifactId );
    current = new File( current, version );
    current.mkdirs();
    return current;
  }

  protected Model createModel( String groupId, String artifactId, String version ) {
    Model pom = new Model();

    pom.setModelVersion( "4.0.0" );
    pom.setGroupId( groupId );
    pom.setArtifactId( artifactId );
    pom.setVersion( version );

    DistributionManagement management = new DistributionManagement();
    management.setDownloadUrl( "http://javafx.com/downloads" );
    pom.setDistributionManagement( management );
    return pom;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy