private File findKickstartJar()

in src/main/java/org/apache/sling/maven/kickstart/run/StartMojo.java [374:439]


    private File findKickstartJar() throws MojoFailureException, MojoExecutionException {

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

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

        // If the current project is a slingstart project, use its JAR artifact
        if (this.project.getPackaging().equals(BuildConstants.PACKAGING_SLINGQUICKSTART)) {
            File jarFile = project.getArtifact().getFile();
            if (jarFile != null && jarFile.exists()) {
                getLog().info("Using kickstart 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 kickstart 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 kickstart 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)
//AS TODO: Is Package Mojo still needed / supported ?
//        File localJarFile = PackageMojo.getNonPrimaryBuildFile(project, ".jar");
//        if (localJarFile.exists()) {
//            getLog().info("Using local kickstart 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_SLINGQUICKSTART.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 kickstart jar from first dependency of type 'slingstart': '"+ d +"'!");
                return getArtifact(d).getFile();
            }
        }

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