Examples of DirectoryResource


Examples of org.jboss.forge.addon.resource.DirectoryResource

   }

   private Project createSubmoduleProject(final Project parent, String moduleName, String artifactId,
            Class<? extends ProjectFacet>... requiredProjectFacets)
   {
      DirectoryResource location = parent.getProjectRoot().getOrCreateChildDirectory(moduleName);

      Set<Class<? extends ProjectFacet>> facets = new LinkedHashSet<Class<? extends ProjectFacet>>();
      facets.add(ForgeContainerAPIFacet.class);
      facets.addAll(Arrays.asList(requiredProjectFacets));
View Full Code Here

Examples of org.jboss.forge.addon.resource.DirectoryResource

      GenerationType idStrategyChosen = idStrategy.getValue();
      if (idStrategyChosen == null)
      {
         idStrategyChosen = GenerationType.AUTO;
      }
      DirectoryResource targetDir = targetLocation.getValue();
      Project project = getSelectedProject(context);
      JavaResource javaResource;
      if (project == null)
      {
         javaResource = persistenceOperations.newEntity(targetDir, entityName, entityPackage, idStrategyChosen,
View Full Code Here

Examples of org.jboss.forge.addon.resource.DirectoryResource

      Thread.sleep(1500);

      System.out.println("OUT:" + test.getStdOut().toString());
      System.out.println("ERR:" + test.getStdErr().toString());

      DirectoryResource projectRoot = (DirectoryResource) resourceFactory.create(target);
      Project project = projectFactory.findProject(projectRoot.getChildDirectory("lincoln"));

      Assert.assertNotNull(project);

      Assert.assertTrue(project.getRoot().exists());
View Full Code Here

Examples of org.jboss.forge.addon.resource.DirectoryResource

   @Test
   public void testEscapes() throws Exception
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      tempDir.deleteOnExit();
      DirectoryResource currentResource = resourceFactory.create(DirectoryResource.class, tempDir);
      Shell shell = test.getShell();
      shell.setCurrentResource(currentResource);
      DirectoryResource child = currentResource.getChildDirectory("Forge 2 Escape");
      child.mkdir();
      child.deleteOnExit();
      Result result = test.execute("cd Forge\\ 2\\ Escape", 10, TimeUnit.SECONDS);
      Assert.assertThat(result.getMessage(), CoreMatchers.nullValue());
      Assert.assertEquals(shell.getCurrentResource(), child);
      currentResource.delete(true);
   }
View Full Code Here

Examples of org.jboss.forge.addon.resource.DirectoryResource

   @Test
   public void testQuotes() throws Exception
   {
      File tempDir = OperatingSystemUtils.createTempDir();
      tempDir.deleteOnExit();
      DirectoryResource currentResource = resourceFactory.create(DirectoryResource.class, tempDir);
      Shell shell = test.getShell();
      shell.setCurrentResource(currentResource);
      FileResource<?> child = currentResource.getChildDirectory("Forge 2 Escape");
      child.mkdir();
      child.deleteOnExit();
      Result result = test.execute("cd \"Forge 2 Escape\"", 10, TimeUnit.SECONDS);
      Assert.assertThat(result.getMessage(), nullValue());
      Assert.assertEquals(shell.getCurrentResource(), child);
      currentResource.delete(true);
   }
View Full Code Here

Examples of org.jboss.forge.addon.resource.DirectoryResource

   @Test(timeout = 10000)
   public void testTransactionTrackChanges() throws Exception
   {
      test.clearScreen();
      DirectoryResource tempDir = factory.create(OperatingSystemUtils.createTempDir()).reify(DirectoryResource.class);
      tempDir.deleteOnExit();

      test.getShell().setCurrentResource(tempDir);
      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Resource change tracking is ON.", SHELL_TIMEOUT, TimeUnit.SECONDS);

      Assert.assertFalse(test.execute("touch foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Created  " + tempDir.getFullyQualifiedName() + File.separator + "foo.txt",
               SHELL_TIMEOUT, TimeUnit.SECONDS);

      Assert.assertFalse(test.execute("rm foo.txt", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Deleted  " + tempDir.getFullyQualifiedName() + File.separator +
               "foo.txt", SHELL_TIMEOUT,
               TimeUnit.SECONDS);

      Assert.assertFalse(test.execute("track-changes", SHELL_TIMEOUT, TimeUnit.SECONDS) instanceof Failed);
      test.waitForStdOutValue("Resource change tracking is OFF.", SHELL_TIMEOUT, TimeUnit.SECONDS);
View Full Code Here

Examples of org.jboss.forge.resource.DirectoryResource

   @Override
   public Result execute(UIContext context) throws Exception
   {
      Result result = Results.success("New project has been created.");
      DirectoryResource directory = targetLocation.getValue();
      DirectoryResource targetDir = directory.getChildDirectory(named.getValue());

      if (targetDir.mkdirs() || overwrite.getValue())
      {
         ProjectType value = type.getValue();

         Project project = null;
         if (value != null)
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

            help = "Install a plugin from a local project folder")
   public void installFromLocalProject(
            @Option(description = "project directory", required = true) final Resource<?> projectFolder,
            final PipeOut out) throws Exception
   {
      DirectoryResource workspace = projectFolder.reify(DirectoryResource.class);
      if ((workspace == null) || !workspace.exists())
      {
         throw new IllegalArgumentException("Project folder must be specified.");
      }

      buildFromCurrentProject(out, workspace);
View Full Code Here

Examples of org.jboss.forge.resources.DirectoryResource

            @Option(name = "ref", description = "branch or tag to build") final String refName,
            @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,
            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();
      }

      try
      {
         ShellMessages.info(out, "Checking out plugin source files to [" + buildDir.getFullyQualifiedName()
                  + "] via 'git'");
         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.");
         }

         buildFromCurrentProject(out, buildDir);
      }
      finally
      {
         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

Examples of org.jboss.forge.resources.DirectoryResource

    * Aborts a forge update
    */
   @Command(value = "update-abort", help = "Aborts a previous forge update")
   public void updateAbort() throws IOException
   {
      DirectoryResource forgeHome = environment.getForgeHome();
      DirectoryResource updateDirectory = forgeHome.getChildDirectory(".update");
      if (updateDirectory.exists())
      {
         if (updateDirectory.delete(true))
         {
            ShellMessages.success(shell,
                     "Update files were deleted. Run 'forge update' if you want to update this installation again.");
         }
         else
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.