Examples of DirectoryResource


Examples of org.jboss.forge.resources.DirectoryResource

    * Updates the forge version
    */
   @Command(value = "update", help = "Update this forge installation")
   public void update() throws IOException
   {
      DirectoryResource forgeHome = environment.getForgeHome();
      DirectoryResource updateDir = forgeHome.getChildDirectory(".update");
      if (updateDir.exists())
      {
         ShellMessages
                  .warn(shell,
                           "There is an update pending. Restart Forge for the update to take effect. To abort this update, type 'forge update-abort'");
         return;
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

   {
      wait.start("Update in progress. Please wait");
      List<DependencyResource> resolvedArtifacts = resolver.resolveArtifacts(dependency);
      Assert.isTrue(resolvedArtifacts.size() == 1, "Artifact was not found");
      DependencyResource resource = resolvedArtifacts.get(0);
      DirectoryResource forgeHome = environment.getForgeHome();
      Files.unzip(resource.getUnderlyingResourceObject(), forgeHome.getUnderlyingResourceObject());

      DirectoryResource childDirectory = forgeHome.getChildDirectory(dependency.getArtifactId() + "-"
               + dependency.getVersion());

      DirectoryResource updateDirectory = forgeHome.getChildDirectory(".update");
      if (updateDirectory.exists())
      {
         updateDirectory.delete(true);
      }
      childDirectory.renameTo(updateDirectory);
      wait.stop();
      ShellMessages.success(shell, "Forge will now restart to complete the update...");
      System.exit(0);
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

   /*
    * Helpers
    */
   private void buildFromCurrentProject(final PipeOut out, final DirectoryResource buildDir) throws Abort
   {
      DirectoryResource savedLocation = shell.getCurrentDirectory();
      try
      {
         shell.setCurrentResource(buildDir);
         Project project = shell.getCurrentProject();
         if (project == null)
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

            final String apiVersion)
   {

      boolean dependenciesAsResourceRoot = needDependenciesAsResourceRoot(project);

      DirectoryResource moduleDir = getOrCreatePluginModuleDirectory(dep);
      String pluginName = dep.getGroupId() + "." + dep.getArtifactId();
      String pluginSlot = dep.getVersion();

      FileResource<?> moduleXml = (FileResource<?>) moduleDir.getChild("module.xml");
      if (moduleXml.exists()
               && !prompt.promptBoolean(
                        "An existing installation for version [" + pluginSlot
                                 + "] of this plugin was found. Replace it?", true))
      {
         throw new RuntimeException("Aborted.");
      }

      moduleXml.delete();
      moduleXml.createNewFile();

      // <resource-root path="maven-dependency.jar" />
      Node module = XMLParser.parse(getClass().getResourceAsStream(MODULE_TEMPLATE_XML));
      module.attribute("name", pluginName);
      module.attribute("slot", pluginSlot);
      Node resources = module.getSingle("resources");

      resources.createChild("resource-root").attribute("path", dep.getArtifactId() + ".jar");

      if (dependenciesAsResourceRoot)
      {
         writeResourceRoots(project, module, moduleDir, resources);
      }

      // Copy the compiled JAR into the module directory
      FileResource<?> jar = moduleDir.getChild(dep.getArtifactId() + ".jar").reify(FileResource.class);
      jar.createNewFile();
      jar.setContents(artifact.getResourceInputStream());

      // <module name="org.jboss.forge:main" />
      Node dependencies = module.getSingle("dependencies");
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

      }
   }

   private void createDependenciesModule(final Project project, final Dependency dep)
   {
      DirectoryResource dependencyDir = getOrCreatePluginDependenciesModuleDirectory(dep);
      String pluginName = dep.getGroupId() + "." + dep.getArtifactId();
      String pluginSlot = dep.getVersion();

      FileResource<?> moduleXml = (FileResource<?>) dependencyDir.getChild("module.xml");
      moduleXml.delete();
      moduleXml.createNewFile();

      // <resource-root path="maven-dependency.jar" />
      Node module = XMLParser.parse(getClass().getResourceAsStream(MODULE_TEMPLATE_XML));
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

      }
   }

   public DirectoryResource getOrCreatePluginModuleDirectory(final Dependency dep)
   {
      DirectoryResource pluginDir = environment.getPluginDirectory();

      List<String> groupId = Arrays.asList(dep.getGroupId().split("\\."));
      List<String> artifactId = Arrays.asList(dep.getArtifactId().split("\\."));
      DirectoryResource dir = pluginDir;
      for (String segment : groupId)
      {
         dir = dir.getOrCreateChildDirectory(segment);
      }

      for (String segment : artifactId)
      {
         dir = dir.getOrCreateChildDirectory(segment);
      }

      dir = dir.getOrCreateChildDirectory(dep.getVersion());
      return dir;
   }
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

      return dir;
   }

   public DirectoryResource getOrCreatePluginDependenciesModuleDirectory(final Dependency dep)
   {
      DirectoryResource pluginDir = environment.getPluginDirectory();

      List<String> groupId = Arrays.asList(dep.getGroupId().split("\\."));
      List<String> artifactId = Arrays.asList(dep.getArtifactId().split("\\."));
      DirectoryResource dir = pluginDir;
      for (String segment : groupId)
      {
         dir = dir.getOrCreateChildDirectory(segment);
      }

      for (String segment : artifactId)
      {
         dir = dir.getOrCreateChildDirectory(segment);
      }

      dir = dir.getOrCreateChildDirectory("dependencies");
      dir = dir.getOrCreateChildDirectory(dep.getVersion());
      return dir;
   }
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

      this.projectFactory = projectFactory;
   }

   public void doInit(@Observes final InitProject event)
   {
      DirectoryResource currentDirectory = shell.getCurrentDirectory();

      Project newProject = null;

      try
      {
         final DirectoryResource newRoot = projectFactory.findProjectRootRecusively(currentDirectory);
         if (newRoot != null)
         {
            Project oldProject = cp.getCurrent();

            Project temp = new BaseProject()
            {
               @Override
               public DirectoryResource getProjectRoot()
               {
                  return newRoot;
               }

               @Override
               public boolean exists()
               {
                  return false;
               }
            };

            cp.setCurrentProject(temp);

            if (oldProject != null)
            {
               DirectoryResource oldProjectRoot = oldProject.getProjectRoot();
               if (!newRoot.equals(oldProjectRoot))
               {
                  newProject = projectFactory.findProjectRecursively(currentDirectory);
               }
               else
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

   public void installFromLocalProject(
            @Option(description = "project directory", required = true) final Resource<?> projectFolder,
            @Option(name = "coordinates", type = PromptType.DEPENDENCY_ID, description = "the coordinates for the plugin (if in a multi-module repository)") final Dependency coordinates,
            final PipeOut out) throws Exception
   {
      DirectoryResource workspace = projectFolder.reify(DirectoryResource.class);
      if ((workspace == null) || !workspace.exists())
      {
         throw new IllegalArgumentException("Project folder must be specified.");
      }
      pluginManager.installFromProject(workspace, coordinates);
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

            @Option(name = "checkoutDir", description = "directory in which to clone the repository") final Resource<?> checkoutResource,
            @Option(name = "keepSources", description = "keep the sources after checking out", defaultValue = "false", flagOnly = true) final boolean keepSources,
            @Option(name = "coordinates", type = PromptType.DEPENDENCY_ID, description = "the coordinates for the plugin (if in a multi-module repository)") final Dependency coordinates,
            final PipeOut out) throws Exception
   {
      DirectoryResource buildDir;
      if (checkoutResource != null)
      {
         if (!(checkoutResource instanceof FileResource<?>))
         {
            throw new IllegalArgumentException("Checkout dir must be a directory path");
         }
         FileResource<?> checkoutDir = (FileResource<?>) checkoutResource;
         // Resource already exists
         if (checkoutDir.exists())
         {
            // Check if it is already a directory
            if (!checkoutDir.isDirectory())
            {
               throw new RuntimeException("Resource " + checkoutDir.getFullyQualifiedName()
                        + " is not a valid directory.");
            }
            buildDir = checkoutDir.reify(DirectoryResource.class);
            if (!shell.promptBoolean("Directory " + buildDir.getFullyQualifiedName()
                     + " already exists. Do you want to overwrite?", false))
            {
               throw new AbortedException("Directory " + buildDir.getFullyQualifiedName()
                        + " already exists");
            }
            buildDir.delete(true);
            buildDir.mkdirs();
         }
         else
         {
            // Resource does not exist. Create it
            checkoutDir.mkdirs();
            buildDir = checkoutDir.reify(DirectoryResource.class);
         }
      }
      else
      {
         buildDir = shell.getCurrentDirectory().createTempResource();
      }

      Git repo = null;
      try
      {
         ShellMessages.info(out, "Checking out plugin source files to [" + buildDir.getFullyQualifiedName()
                  + "] via 'git'");
         repo = GitUtils.clone(buildDir, gitRepo);

         Ref ref = null;
         String targetRef = refName;
         if (targetRef == null)
         {
            // Default to Forge runtime version if no Ref name is supplied.
            targetRef = environment.getRuntimeVersion();
         }

         if (targetRef != null)
         {
            // Try to find a Tag matching the given Ref name or runtime version
            Map<String, Ref> tags = repo.getRepository().getTags();
            ref = tags.get(targetRef);

            // Now try to find a matching Branch
            if (ref == null)
            {
               List<Ref> refs = GitUtils.getRemoteBranches(repo);
               for (Ref branchRef : refs)
               {
                  String branchName = branchRef.getName();
                  if (branchName != null && branchName.endsWith(targetRef))
                  {
                     ref = repo.branchCreate().setName(targetRef).setUpstreamMode(SetupUpstreamMode.TRACK)
                              .setStartPoint("origin/" + targetRef).call();
                  }
               }
            }

            // Now try to find a tag or branch with same Major.Minor.(x) version.
            if (ref == null)
            {
               // All
               List<String> sortedVersions = new ArrayList<String>();

               // Branches
               for (Ref branchRef : GitUtils.getRemoteBranches(repo))
               {
                  String branchName = branchRef.getName();
                  branchName = branchName.replaceFirst("refs/heads/", "");
                  if (InstalledPluginRegistry.isApiCompatible(targetRef, branchName))
                     sortedVersions.add(branchName);
               }

               // Tags

               // Branches
               for (String tag : tags.keySet())
               {
                  if (InstalledPluginRegistry.isApiCompatible(targetRef, tag))
                     sortedVersions.add(tag);
               }

               // Sort
               Collections.sort(sortedVersions);

               if (!sortedVersions.isEmpty())
               {
                  String version = sortedVersions.get(sortedVersions.size() - 1);
                  if (InstalledPluginRegistry.isApiCompatible(targetRef, version))
                  {
                     ref = tags.get(version);

                     if (ref == null)
                     {
                        ref = repo.branchCreate().setName(version).setUpstreamMode(SetupUpstreamMode.TRACK)
                                 .setStartPoint("origin/" + version).call();
                     }
                  }
               }
            }
         }

         if (ref == null)
         {
            ref = repo.getRepository().getRef("master");
         }

         if (ref != null)
         {
            ShellMessages.info(out, "Switching to branch/tag [" + ref.getName() + "]");
            GitUtils.checkout(repo, ref, false, SetupUpstreamMode.TRACK, false);
         }
         else if (refName != null)
         {
            throw new RuntimeException("Could not locate ref [" + targetRef + "] in repository ["
                     + repo.getRepository().getDirectory().getAbsolutePath() + "]");
         }
         else
         {
            ShellMessages.warn(
                     out,
                     "Could not find a Ref matching the current Forge version ["
                              + environment.getRuntimeVersion()
                              + "], building Plugin from HEAD.");
         }
         pluginManager.installFromProject(buildDir, coordinates);
      }
      finally
      {
         GitUtils.close(repo);
         if (buildDir != null)
         {
            if (keepSources)
            {
               ShellMessages.info(out,
                        "Sources are kept in [" + buildDir.getFullyQualifiedName() + "]");
            }
            else
            {
               ShellMessages.info(out,
                        "Cleaning up temp workspace [" + buildDir.getFullyQualifiedName()
                                 + "]");
               buildDir.delete(true);
            }
         }
      }

      ShellMessages.success(out, "Installed from [" + gitRepo + "] successfully.");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.