private File findLaunchpadJar()

in src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java [366:430]


    private File findLaunchpadJar() throws MojoFailureException, MojoExecutionException {

        // If a launchpad JAR is specified, use it
        if (launchpadJar != null) {
            getLog().info("Using launchpad jar from '" +  launchpadJar + "' given as configuration parameter!");
            return launchpadJar;
        }

        // If a launchpad dependency is configured, resolve it
        if (launchpadDependency != null) {
            getLog().info("Using launchpad dependency '" +  launchpadDependency + "' given as configuration parameter!");
            return getArtifact(launchpadDependency).getFile();
        }

        // If the current project is a slingstart project, use its JAR artifact
        if (this.project.getPackaging().equals(BuildConstants.PACKAGING_SLINGSTART)) {
            File jarFile = project.getArtifact().getFile();
            if (jarFile != null && jarFile.exists()) {
                getLog().info("Using launchpad jar being generated as this project's primary artifact: '" +  jarFile + "'!");
                return jarFile;
            }
            else {
                jarFile = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar");
                if (jarFile.exists()) {
                    getLog().info("Using launchpad jar being generated as this project's primary artifact: '" +  jarFile + "'!");
                    return jarFile;
                }
            }
        }

        // In case there was a provisioning model found but this is not a slingstart project, the JAR might be attached already through goal "package"
        for (Artifact attachedArtifact : project.getAttachedArtifacts()) {
            // find the attached artifact with classifier "standalone"
            if (BuildConstants.TYPE_JAR.equals(attachedArtifact.getType()) && BuildConstants.CLASSIFIER_APP.equals(attachedArtifact.getClassifier())) {
                getLog().info("Using launchpad jar being attached as additional project artifact: '" +  attachedArtifact.getFile() + "'!");
                return attachedArtifact.getFile();
            }
        }
        
        // also check for jars in known target folders (in case the jar has been created in this project's target folder but not attached to the Maven project)
        File localJarFile = PackageMojo.getNonPrimaryBuildFile(project, ".jar");
        if (localJarFile.exists()) {
            getLog().info("Using local launchpad jar being created in predefined directory: '" +  localJarFile + "'!");
            return localJarFile;
        }
        
        // Last chance: use the first declared dependency with type "slingstart"
        final Set<Artifact> dependencies = this.project.getDependencyArtifacts();
        for (final Artifact dep : dependencies) {
            if (BuildConstants.PACKAGING_SLINGSTART.equals(dep.getType())) {
                final Dependency d = new Dependency();
                d.setGroupId(dep.getGroupId());
                d.setArtifactId(dep.getArtifactId());
                d.setVersion(dep.getVersion());
                d.setScope(Artifact.SCOPE_RUNTIME);
                d.setType(BuildConstants.TYPE_JAR);
                getLog().info("Using launchpad jar from first dependency of type 'slingstart': '"+ d +"'!");
                return getArtifact(d).getFile();
            }
        }

        // Launchpad has not been found, throw an exception
        throw new MojoFailureException("Could not find the launchpad jar. " +
                "Either specify the 'launchpadJar' configuration or use this inside a slingstart project.");
    }