Skip to content

Commit

Permalink
FORGE-2283: Provide a method for updating whole distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Briskar authored and gastaldi committed Jul 13, 2015
1 parent 865f336 commit 7e446bc
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 35 deletions.
8 changes: 8 additions & 0 deletions addon-manager/addon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
<classifier>forge-addon</classifier>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>dependencies</artifactId>
<classifier>forge-addon</classifier>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>projects</artifactId>
Expand Down
1 change: 0 additions & 1 deletion addon-manager/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,5 @@
<artifactId>projects-api</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.TreeSet;

import javax.inject.Inject;

import org.jboss.forge.addon.manager.impl.utils.CoordinateUtils;
import org.jboss.forge.addon.ui.command.AbstractUICommand;
import org.jboss.forge.addon.ui.context.UIBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jboss.forge.addon.manager.impl.utils.DistributionDirectoryExistsPredicate;
import org.jboss.forge.addon.resource.DirectoryResource;
import org.jboss.forge.addon.resource.ResourceFactory;
import org.jboss.forge.addon.resource.zip.ZipFileResource;
import org.jboss.forge.addon.ui.annotation.Command;
import org.jboss.forge.addon.ui.annotation.predicate.NonGUIEnabledPredicate;
import org.jboss.forge.addon.ui.input.UIPrompt;
Expand All @@ -43,16 +44,17 @@
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*/
public class DistributionCommand
public class ForgeUpdateDistributionCommand
{
@Inject
private DependencyResolver resolver;

@Inject
private ResourceFactory resourceFactory;

@Command(value = "Forge: Update Abort", help = "Aborts a previous forge update", categories = { "Forge", "Manage" }, enabled = {
NonGUIEnabledPredicate.class, DistributionDirectoryExistsPredicate.class })
@Command(value = "Forge: Update Abort", help = "Aborts a previous forge update", categories = { "Forge",
"Manage" }, enabled = {
NonGUIEnabledPredicate.class, DistributionDirectoryExistsPredicate.class })
public Result updateAbort() throws IOException
{
DirectoryResource forgeHome = getForgeHome();
Expand All @@ -75,7 +77,8 @@ public Result updateAbort() throws IOException
}
}

@Command(value = "Forge: Update", help = "Update this forge installation", categories = { "Forge", "Manage" }, enabled = NonGUIEnabledPredicate.class)
@Command(value = "Forge: Update", help = "Update this forge installation", categories = { "Forge",
"Manage" }, enabled = NonGUIEnabledPredicate.class)
public void update(UIOutput output, UIPrompt prompt, UIProgressMonitor monitor) throws IOException
{
PrintStream out = output.out();
Expand Down Expand Up @@ -116,22 +119,15 @@ private DirectoryResource getForgeHome()
private void updateForge(final DirectoryResource forgeHome, final Coordinate forgeDistribution, UIOutput output)
throws IOException
{
// wait.start("Update in progress. Please wait");
Dependency dependency = resolver.resolveArtifact(DependencyQueryBuilder.create(forgeDistribution));
Assert.notNull(dependency, "Artifact was not found");
resourceFactory.create(dependency.getArtifact().getUnderlyingResourceObject());
// Files.unzip(resource.getUnderlyingResourceObject(), forgeHome.getUnderlyingResourceObject());

ZipFileResource dependencyZip = resourceFactory.create(ZipFileResource.class,
dependency.getArtifact().getUnderlyingResourceObject());
dependencyZip.extractTo(forgeHome);
DirectoryResource childDirectory = forgeHome.getChildDirectory(dependency.getCoordinate().getArtifactId() + "-"
+ dependency.getCoordinate().getVersion());

DirectoryResource updateDirectory = forgeHome.getChildDirectory(".update");
if (updateDirectory.exists())
{
updateDirectory.delete(true);
}
childDirectory.renameTo(updateDirectory);
// wait.stop();
output.success(output.out(), "Forge will now restart to complete the update...");
System.exit(0);
}
Expand Down Expand Up @@ -160,8 +156,7 @@ public boolean accept(Dependency dependency)
return version.compareTo(runtimeVersion) > 0 && version.getMajorVersion() == 2
&& version.getQualifier().equals("Final");
}
}
));
}));
List<Coordinate> versions = resolver.resolveVersions(query);
return versions.isEmpty() ? null : versions.get(versions.size() - 1);
}
Expand Down
23 changes: 23 additions & 0 deletions addon-manager/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
<artifactId>furnace-test-harness</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.furnace.test</groupId>
<artifactId>arquillian-furnace-classpath</artifactId>
Expand Down Expand Up @@ -90,8 +96,25 @@
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jar</nonFilteredFileExtension>
<nonFilteredFileExtension>zip</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</execution>
<execution>
<id>copy-test-files</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/test-classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/test/resources/test-files</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-repository</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.arquillian.AddonDeployment;
import org.jboss.forge.arquillian.AddonDeployments;
import org.jboss.forge.arquillian.AddonDependencies;
import org.jboss.forge.arquillian.archive.AddonArchive;
import org.jboss.forge.furnace.addons.Addon;
import org.jboss.forge.furnace.addons.AddonId;
import org.jboss.forge.furnace.addons.AddonRegistry;
import org.jboss.forge.furnace.manager.AddonManager;
import org.jboss.forge.furnace.manager.maven.MavenContainer;
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.forge.furnace.util.Addons;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.AfterClass;
Expand Down Expand Up @@ -84,21 +82,12 @@ public static void clearRemoteRepository()
}

@Deployment
@AddonDeployments({
@AddonDeployment(name = "org.jboss.forge.addon:addon-manager"),
@AddonDeployment(name = "org.jboss.forge.addon:maven")
})
@AddonDependencies
public static AddonArchive getDeployment()
{
AddonArchive archive = ShrinkWrap
.create(AddonArchive.class)
.addBeansXML()
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"),
AddonDependencyEntry.create("org.jboss.forge.addon:maven"),
AddonDependencyEntry.create("org.jboss.forge.addon:addon-manager")
);

.addBeansXML();
return archive;
}

Expand Down
Binary file not shown.
16 changes: 16 additions & 0 deletions dist/src/main/resources/bin/forge
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ fi

echo Using Forge at $FORGE_HOME

# If there is update prepared (.update directory), copy files from it
if [ -e "$FORGE_HOME/.update" ] ; then
rm -rf $FORGE_HOME/addons
mv $FORGE_HOME/.update/addons $FORGE_HOME/addons
rm -rf $FORGE_HOME/bin
mv $FORGE_HOME/.update/bin $FORGE_HOME/bin
rm -rf $FORGE_HOME/lib
mv $FORGE_HOME/.update/lib $FORGE_HOME/lib
rm -rf $FORGE_HOME/.update
cd ..
cd bin
echo "Restarting Forge to new version"
sh forge $QUOTED_ARGS
exit 0
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$FORGE_HOME" ] &&
Expand Down
21 changes: 21 additions & 0 deletions dist/src/main/resources/bin/forge.bat
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ goto runForge
@REM Start Forge
:runForge

@REM If there is update prepared (.update directory), copy files from it
if exist "%FORGE_HOME%\.update" (
rmdir /S/Q "%FORGE_HOME%\addons"
move /y "%FORGE_HOME%\.update\addons\*" "%FORGE_HOME%\addons\*"

rmdir /S/Q "%FORGE_HOME%\bin"
move /y "%FORGE_HOME%\.update\bin\*" "%FORGE_HOME%\bin\*"

rmdir /S/Q "%FORGE_HOME%\lib"
move /y "%FORGE_HOME%\.update\lib\*" "%FORGE_HOME%\lib\*"

rmdir /S/Q "%FORGE_HOME%\.update"

cd ..
cd bin
echo "Restarting Forge to newer version."
CALL forge.bat %*
exit /b
)


if exist "%FORGE_HOME%\addons" set ADDONS_DIR=--immutableAddonDir "%FORGE_HOME%\addons"
set FORGE_MAIN_CLASS=org.jboss.forge.bootstrap.Bootstrap
%FORGE_JAVA_EXE% %FORGE_DEBUG_ARGS% %FORGE_OPTS% "-Dforge.standalone=true" "-Dforge.home=%FORGE_HOME%" ^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.jboss.forge.addon.ui.command;

import org.jboss.forge.furnace.addons.AddonId;

/**
* Responsible for providing {@link UICommand} instances.
*
Expand All @@ -17,4 +19,10 @@ public interface CommandProvider
* Get all {@link UICommand} instances from this {@link CommandProvider}.
*/
Iterable<UICommand> getCommands();

/**
* Clear all the cached data for the given addon.
* Mainly usable for testing purposes, when an addon is manually undeployed but it's annotated commands stay cached.
*/
void addonUndeployed(AddonId addonId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.jboss.forge.addon.ui.command.CommandProvider;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.furnace.addons.AddonId;
import org.jboss.forge.furnace.addons.AddonRegistry;

/**
Expand All @@ -28,4 +29,10 @@ public Iterable<UICommand> getCommands()
return registry.getServices(UICommand.class);
}

@Override
public void addonUndeployed(AddonId addonId)
{
//don't do anything because this provider does not store any cache data
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ private UICommand createAnnotatedCommand(Method method)
public void addonDestroyed(@Observes PreShutdown shutdown)
{
AddonId id = shutdown.getAddon().getId();
extension.addonDestroyed(id);
addonUndeployed(id);
}

@Override
public void addonUndeployed(AddonId addonId)
{
extension.addonDestroyed(addonId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class UITestHarness
private CommandControllerFactory factory;

private UIProviderImpl providerImpl;

private boolean isGui = true;

private final Map<String, String> promptResults = new HashMap<>();

Expand Down Expand Up @@ -137,11 +139,11 @@ public UIProviderImpl getProvider()
{
if (providerImpl == null)
{
providerImpl = new UIProviderImpl(true);
providerImpl = new UIProviderImpl(isGui);
}
return providerImpl;
}

private UIContextImpl getUIContextInstance(Resource<?>... initialSelection)
{
Imported<UIContextListener> listeners = addonRegistry.getServices(UIContextListener.class);
Expand All @@ -157,4 +159,14 @@ public Map<String, String> getPromptResults()
{
return this.promptResults;
}

public boolean isGui()
{
return isGui;
}

public void setGui(boolean isGui)
{
this.isGui = isGui;
}
}

0 comments on commit 7e446bc

Please sign in to comment.