-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User configuration injection is now working
- Loading branch information
Showing
10 changed files
with
168 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
...ration/impl/src/main/java/org/jboss/forge/addon/configuration/ConfigAdapterQualifier.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
...impl/src/main/java/org/jboss/forge/addon/configuration/ConfigAdapterQualifierLiteral.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...uration/impl/src/main/java/org/jboss/forge/addon/configuration/ConfigurationProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.configuration; | ||
|
||
import java.io.File; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
|
||
import org.apache.commons.configuration.XMLConfiguration; | ||
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy; | ||
import org.jboss.forge.addon.projects.Project; | ||
import org.jboss.forge.addon.resource.FileResource; | ||
import org.jboss.forge.furnace.util.OperatingSystemUtils; | ||
|
||
@ApplicationScoped | ||
public class ConfigurationProducer | ||
{ | ||
|
||
private ScopedConfigurationAdapter userConfig; | ||
private ScopedConfigurationAdapter projectConfig; | ||
|
||
@Produces | ||
// public Configuration getConfiguration() throws ConfigurationException | ||
// { | ||
// FileResource<?> projectSettings = getProjectSettings(); | ||
// if ((project != null) && !project.equals(this.currentProject)) | ||
// { | ||
// ScopedConfigurationAdapter projectConfig = new ScopedConfigurationAdapter(); | ||
// XMLConfiguration projectLocalConfig; | ||
// try | ||
// { | ||
// projectLocalConfig = new XMLConfiguration(getProjectSettings().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 = new ConfigurationAdapter(projectConfig, projectLocalConfig); | ||
// 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(); | ||
// } | ||
// | ||
public Configuration getUserConfig() throws ConfigurationException | ||
{ | ||
// FIXME NPE caused when no project exists because config param is null | ||
if (userConfig == null) | ||
{ | ||
XMLConfiguration globalXml; | ||
try | ||
{ | ||
File userConfigurationFile = new File(OperatingSystemUtils.getUserForgeDir(), "config.xml"); | ||
globalXml = new XMLConfiguration(userConfigurationFile); | ||
globalXml.setEncoding("UTF-8"); | ||
} | ||
catch (org.apache.commons.configuration.ConfigurationException e) | ||
{ | ||
throw new ConfigurationException(e); | ||
} | ||
globalXml.setReloadingStrategy(new FileChangedReloadingStrategy()); | ||
globalXml.setAutoSave(true); | ||
|
||
ConfigurationAdapter adapter = new ConfigurationAdapter(null, globalXml); | ||
userConfig = new ScopedConfigurationAdapter(ConfigurationScope.USER, adapter); | ||
} | ||
return userConfig; | ||
} | ||
|
||
private FileResource<?> getProjectSettings() | ||
{ | ||
final Project project = null; | ||
FileResource<?> settingsFile = project.getProjectRoot().getChild(".forge_settings").reify(FileResource.class); | ||
return settingsFile; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
configuration/tests/src/test/java/org/jboss/forge/addon/AbstractTestCase.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...ration/tests/src/test/java/org/jboss/forge/addon/configuration/ConfigurationImplTest.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
configuration/tests/src/test/java/org/jboss/forge/addon/configuration/ConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.configuration; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.arquillian.Addon; | ||
import org.jboss.forge.arquillian.Dependencies; | ||
import org.jboss.forge.arquillian.archive.ForgeArchive; | ||
import org.jboss.forge.furnace.addons.AddonId; | ||
import org.jboss.forge.furnace.repositories.AddonDependencyEntry; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Arquillian.class) | ||
public class ConfigurationTest | ||
{ | ||
|
||
@Deployment | ||
@Dependencies({ | ||
@Addon(name = "org.jboss.forge.addon:configuration", version = "2.0.0-SNAPSHOT") | ||
}) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
ForgeArchive archive = ShrinkWrap | ||
.create(ForgeArchive.class) | ||
.addBeansXML() | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create(AddonId.from("org.jboss.forge.addon:configuration", | ||
"2.0.0-SNAPSHOT")) | ||
); | ||
return archive; | ||
} | ||
|
||
@Inject | ||
private Configuration configuration; | ||
|
||
@Test | ||
public void testConfigurationInjection() throws Exception | ||
{ | ||
assertNotNull(configuration); | ||
} | ||
} |