Package org.jboss.forge.project

Examples of org.jboss.forge.project.Project


   @Override
   public Project createProject(final DirectoryResource dir)
   {
      Resource<?> pom = dir.getChild("pom.xml");

      Project result = null;
      if (pom.exists())
      {
         result = new ProjectImpl(factory, dir);
         Facet facet = coreFacetInstance.get();
         facet.setProject(result);
         result.registerFacet(facet);
      }
      return result;
   }
View Full Code Here


   private ProjectFactory factory;

   @Override
   public Project createProject(final DirectoryResource dir)
   {
      Project result = null;
      if ((dir != null) && dir.exists())
      {
         result = new ProjectImpl(factory, dir);
      }
      return result;
View Full Code Here

    @Unwraps
    public Configuration getConfiguration() throws ConfigurationException
    {
       
        Project project = shell.getCurrentProject();
        if ((project != null) && !project.equals(this.currentProject))
        {
            currentProject = project;
            ScopedConfigurationAdapter projectConfig = new ScopedConfigurationAdapter();
            XMLConfiguration projectLocalConfig;
            try
            {
                projectLocalConfig = new XMLConfiguration(getProjectSettings(project).getUnderlyingResourceObject());
                projectLocalConfig.setEncoding("UTF-8");
            }
            catch (org.apache.commons.configuration.ConfigurationException e)
            {
                throw new ConfigurationException(e);
            }
            projectLocalConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
            projectLocalConfig.setAutoSave(true);

            ConfigurationAdapter adapter = BeanManagerUtils.getContextualInstance(bm, ConfigurationAdapter.class, new ConfigAdapterQualifierLiteral());
            adapter.setParent(projectConfig);
            adapter.setDelegate(projectLocalConfig);
            adapter.setBeanManager(bm);
            projectConfig.setScopedConfiguration(ConfigurationScope.PROJECT, adapter);
            projectConfig.setScopedConfiguration(ConfigurationScope.USER, getUserConfig());

            this.projectConfig = projectConfig;
            return projectConfig;
        }
        else if ((project != null) && project.equals(this.currentProject))
        {
            return projectConfig;
        }
        return getUserConfig();
    }
View Full Code Here

    {
        DirectoryResource savedLocation = shell.getCurrentDirectory();
        try
        {
            shell.setCurrentResource(buildDir);
            Project project = shell.getCurrentProject();
            if (project == null)
            {
                throw new IllegalStateException("Unable to recognise plugin project in ["
                            + buildDir.getFullyQualifiedName() + "]");
            }

            DependencyFacet deps = project.getFacet(DependencyFacet.class);
            DependencyBuilder shellApi = DependencyBuilder.create("org.jboss.forge:forge-shell-api");

            String apiVersion = null;
            if (!deps.hasEffectiveDependency(shellApi)
                        && !prompt.promptBoolean(
                                    "The project does not appear to be a Forge Plugin Project, install anyway?",
                                    false))
            {
                throw new Abort("Installation aborted");
            }
            else
            {
                if (apiVersion == null)
                {
                    Dependency directDependency = deps.getDirectDependency(shellApi);
                    if ((directDependency != null) && !Strings.isNullOrEmpty(directDependency.getVersion()))
                        apiVersion = directDependency.getVersion();
                }

                if (apiVersion == null)
                {
                    // Fall back to checking managed dependencies for a version
                    Dependency managedDependency = deps.getManagedDependency(shellApi);
                    if ((managedDependency != null) && !Strings.isNullOrEmpty(managedDependency.getVersion()))
                        apiVersion = managedDependency.getVersion();
                }

                if (apiVersion == null)
                {
                    // Now completely give up and just use the result from the build
                    Dependency effectiveDependency = deps.getEffectiveDependency(shellApi);
                    if (effectiveDependency != null)
                        apiVersion = effectiveDependency.getVersion();
                    else
                        apiVersion = environment.getRuntimeVersion();
                }
            }

            /**
             * Make sure that our PROVIDED modules are not included in the module dependencies
             */
            // TODO Weld bug requires us to correct /add module for Seam Render dependency
            List<String> groupIds = Arrays.asList("org.jboss.seam.render", "org.jboss.forge");
            List<Dependency> dependencies = deps.getDependencies();
            for (Dependency dependency : dependencies)
            {
                if (groupIds.contains(dependency.getGroupId())
                            && !(ScopeType.PROVIDED.equals(dependency.getScopeTypeEnum())
                            || ScopeType.TEST.equals(dependency.getScopeTypeEnum())))
                {
                    ShellMessages.warn(out, "Dependency [" + dependency.toCoordinates()
                                + "] was not correctly marked as PROVIDED scope; this has been corrected.");
                    deps.addDirectDependency(DependencyBuilder.create(dependency).setScopeType(ScopeType.PROVIDED));
                }
            }

            ShellMessages.info(out, "Invoking build with underlying build system.");
            Resource<?> artifact = project.getFacet(PackagingFacet.class).createBuilder().runTests(false).build();
            if ((artifact != null) && artifact.exists())
            {
                MetadataFacet meta = project.getFacet(MetadataFacet.class);
                Dependency dep = meta.getOutputDependency();

                ShellMessages.info(out, "Installing plugin artifact.");

                // TODO Figure out a better plugin versioning strategy than random numbers, also see if unloading is
View Full Code Here

   @Override
   public List<Object> getCompletionTokens()
   {
      List<Object> result = new ArrayList<Object>();

      Project project = shell.getCurrentProject();
      for (Class<? extends Facet> type : factory.getFacetTypes())
      {
         if (project.hasFacet(type))
         {
            result.add(ConstraintInspector.getName(type));
         }
      }
View Full Code Here

   @Override
   public List<Object> getCompletionTokens()
   {
      List<Object> result = new ArrayList<Object>();

      Project project = shell.getCurrentProject();
      for (Class<? extends Facet> type : factory.getFacetTypes())
      {
         if (!project.hasFacet(type))
         {
            result.add(ConstraintInspector.getName(type));
         }
      }
View Full Code Here

   @Override
   public List<Object> getCompletionTokens()
   {
      List<Object> result = new ArrayList<Object>();

      Project project = shell.getCurrentProject();
      for (Class<? extends Facet> type : factory.getFacetTypes())
      {
         if (project.hasFacet(type))
         {
            result.add(ConstraintInspector.getName(type));
         }
      }
View Full Code Here

   @Override
   public List<Object> getCompletionTokens()
   {
      List<Object> result = new ArrayList<Object>();

      Project project = shell.getCurrentProject();
      for (Class<? extends Facet> type : factory.getFacetTypes())
      {
         if (!project.hasFacet(type))
         {
            result.add(ConstraintInspector.getName(type));
         }
      }
View Full Code Here

   @DefaultCommand
   public void run(@Option(description = "The new directory", defaultValue = "~") Resource<?> r)
   {
      if (r != null)
      {
         Project currentProject = shell.getCurrentProject();
         if (!r.exists())
         {
            if ("~".equals(r.getName()) && currentProject.exists())
            {
               r = currentProject.getProjectRoot();
            }
            else
               throw new RuntimeException("no such resource: " + r.toString());
         }

         String fullyQualifiedName = r.getFullyQualifiedName();
         String userHomePath = OSUtils.getUserHomePath();

         if (fullyQualifiedName.startsWith(userHomePath)
                  && "~".equals(r.getFullyQualifiedName().substring(userHomePath.length())))
         {
            r = currentProject.getProjectRoot();
         }

         shell.setCurrentResource(r);
      }
   }
View Full Code Here

      if (!dir.exists())
      {
         dir.mkdirs();
      }

      Project project = null;

      if (type.equals(PackagingType.JAR) || type.equals(PackagingType.BUNDLE))
      {
         project = projectFactory.createProject(dir,
                  DependencyFacet.class,
                  MetadataFacet.class,
                  JavaSourceFacet.class,
                  ResourceFacet.class);
      }
      else if (type.equals(PackagingType.WAR))
      {
         project = projectFactory.createProject(dir,
                  DependencyFacet.class,
                  MetadataFacet.class,
                  WebResourceFacet.class,
                  JavaSourceFacet.class,
                  ResourceFacet.class);
      }
      else
      {
         project = projectFactory.createProject(dir,
                  DependencyFacet.class,
                  MetadataFacet.class);
      }

      DirectoryResource parentDir = project.getProjectRoot().getParent().reify(DirectoryResource.class);
      if (parentDir != null)
      {
         for (ProjectAssociationProvider provider : providers)
         {
            if (provider.canAssociate(project, parentDir)
                     && shell.promptBoolean("Add new project as a sub-project of [" + parentDir.getFullyQualifiedName()
                              + "]?"))
            {
               provider.associate(project, parentDir);
            }
         }
      }

      MetadataFacet meta = project.getFacet(MetadataFacet.class);
      meta.setProjectName(name);
      meta.setTopLevelPackage(javaPackage);

      PackagingFacet packaging = project.getFacet(PackagingFacet.class);
      packaging.setPackagingType(type);

      DependencyFacet deps = project.getFacet(DependencyFacet.class);
      deps.addRepository(KnownRepository.JBOSS_NEXUS);

      if (packaging.getPackagingType().equals(PackagingType.JAR) && createMain)
      {
         project.getFacet(JavaSourceFacet.class).saveJavaSource(JavaParser
                  .create(JavaClass.class)
                  .setPackage(javaPackage)
                  .setName("Main")
                  .addMethod("public static void main(String[] args) {}")
                  .setBody("System.out.println(\"Hi there! I was forged as part of the project you call " + name
                           + ".\");")
                  .getOrigin());
      }

      if (project.hasFacet(JavaSourceFacet.class))
      {
         DirectoryResource sourceFolder = project.getFacet(JavaSourceFacet.class).getSourceFolder();
         createTopLevelPackage(sourceFolder, javaPackage);
      }

      if (finalName != null)
      {
         packaging.setFinalName(finalName);
      }
      else
      {
         packaging.setFinalName(name);
      }

      /*
       * Only change the environment after success!
       */
      shell.setCurrentResource(project.getProjectRoot());
      ShellMessages.success(out,
               "Created project [" + name + "] in new working directory [" + dir.getFullyQualifiedName() + "]");
   }
View Full Code Here

TOP

Related Classes of org.jboss.forge.project.Project

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.