Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBIDE-22601 - fix regression causing error starting rse.mgmt profile … #429

Merged
merged 1 commit into from Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal;

import java.io.File;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.wst.server.core.IRuntime;
Expand Down Expand Up @@ -47,6 +49,10 @@ public LocalServerModeDetails(IServer server) {

@Override
public String getProperty(String prop) {
if( SEPARATOR_CHAR.equals(prop)) {
return Character.toString(File.separatorChar);
}

IRuntime rt = getServerOrWC().getRuntime();
if( PROP_SERVER_HOME.equals(prop)) {
return rt == null ? null : rt.getLocation().toOSString();
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014 Red Hat, Inc.
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand All @@ -24,7 +24,6 @@
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IFilesystemController;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IServerDetailsController;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ISubsystemController;
import org.jboss.tools.as.core.server.controllable.systems.IDeploymentOptionsController;

public class ServerHomeValidationUtility {
private ISubsystemController findDependencyFromBehavior(IServer server, String system) throws CoreException {
Expand All @@ -49,23 +48,27 @@ public IStatus validateServerHome(IServer server, boolean alwaysThrow) throws Co

IFilesystemController fs = (IFilesystemController)findDependencyFromBehavior(server, IFilesystemController.SYSTEM_ID);
IServerDetailsController det = (IServerDetailsController)findDependencyFromBehavior(server, IServerDetailsController.SYSTEM_ID);
IDeploymentOptionsController opts = (IDeploymentOptionsController)findDependencyFromBehavior(server, IDeploymentOptionsController.SYSTEM_ID);
IStatus s = validateServerHome(server, det, opts, fs);
IStatus s = validateServerHome(server, det, fs);
if( alwaysThrow && !s.isOK()) {
throw new CoreException(s);
}
return s;
}

public IStatus validateServerHome(IServer server, IServerDetailsController details,
IDeploymentOptionsController options, IFilesystemController fs) throws CoreException {
IFilesystemController fs) throws CoreException {
if( details != null ) {
String serverHome = details.getProperty(IServerDetailsController.PROP_SERVER_HOME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are breaking API of a public class/method here. Do we really have to do it? Why not deprecate the old method and add a new one. You can ignore options here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the class is only a month old and nobody else uses it yet. In fact the introduction of this class is what broke the code in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. thanks

if( serverHome.isEmpty()) {
if( serverHome == null || serverHome.isEmpty()) {
return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
NLS.bind("The home directory for \"{0}\" cannot be empty.", server.getName())); //$NON-NLS-1$
}
IPath remoteHome = new RemotePath(serverHome, options.getPathSeparatorCharacter());
String sep2 = details.getProperty(IServerDetailsController.SEPARATOR_CHAR);
if( sep2 == null || sep2.length() != 1 ) {
return (new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
NLS.bind("The separator character for \"{0}\" is invalid: " + sep2, server.getName()))); //$NON-NLS-1$
}
IPath remoteHome = new RemotePath(serverHome, sep2.charAt(0));
if( !fs.exists(remoteHome, new NullProgressMonitor())) {
return (new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
NLS.bind("The home directory for \"{0}\" does not exist: " + serverHome, server.getName()))); //$NON-NLS-1$
Expand Down
Expand Up @@ -34,6 +34,10 @@ public RSEServerModeDetails(IServer server) {

@Override
public String getProperty(String prop) {
if( SEPARATOR_CHAR.equals(prop)) {
return Character.toString(RSEUtils.getRemoteSystemSeparatorCharacter(getServerOrWC()));
}

char sep = RSEUtils.getRemoteSystemSeparatorCharacter(getServerOrWC());
if( PROP_SERVER_HOME.equals(prop)) {
return RSEUtils.getRSEHomeDir(getServerOrWC());
Expand Down
Expand Up @@ -96,6 +96,14 @@ public interface IServerModeDetails {
public static final String PROP_SERVER_TMP_DEPLOYMENTS_FOLDER_ABS = "PROP_SERVER_TMP_DEPLOYMENTS_FOLDER_ABSOLUTE";


/**
* Get the separator character to use for this server
* This property would be much more relevant on the filesystem controller,
* but it is not convenient to change that API without breaking clients.
*
* The return should be a string of length 1, representing 1 character
*/
public static final String SEPARATOR_CHAR = "SEPARATOR_CHAR";

/**
* Retrieve the server-mode-relative value for the given property
Expand Down
3 changes: 2 additions & 1 deletion as/tests/org.jboss.tools.as.test.core/META-INF/MANIFEST.MF
Expand Up @@ -83,7 +83,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.wst.xml.ui;bundle-version="1.1.401",
org.eclipse.wst.xml.core;bundle-version="1.1.900",
org.eclipse.wst.dtd.core;bundle-version="1.1.700",
org.eclipse.wst.xsd.core;bundle-version="1.1.900"
org.eclipse.wst.xsd.core;bundle-version="1.1.900",
org.jboss.tools.locus.mockito;bundle-version="1.9.5"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.jboss.tools.as.test.core,
Expand Down
@@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.as.test.core.subsystems;

import java.util.Collection;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.jboss.ide.eclipse.as.core.util.JBossServerBehaviorUtils;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IPublishController;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ISubsystemController;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ServerProfileModel;
import org.jboss.tools.as.core.server.controllable.systems.IDeploymentOptionsController;
import org.jboss.tools.as.test.core.internal.utils.MatrixUtils;
import org.jboss.tools.as.test.core.internal.utils.ServerCreationTestUtils;
import org.jboss.tools.as.test.core.internal.utils.ServerParameterUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import junit.framework.TestCase;

@RunWith(value = Parameterized.class)
public class DeploymentOptionsSubsystemResolutionTest extends TestCase {
private String serverType;
private String mode;
private IServer server;
@Parameters
public static Collection<Object[]> data() {
String[] servers = ServerParameterUtils.getJBossServerTypeParameters();
String[] modes = new String[]{"local", "rse", "local.mgmt", "rse.mgmt", null};
return MatrixUtils.toMatrix(new Object[][]{servers, modes});
}

public DeploymentOptionsSubsystemResolutionTest(String serverType, String mode) {
this.serverType = serverType;
this.mode = mode;
}

@Before
public void setUp() throws Exception {
server = ServerCreationTestUtils.createMockServerWithRuntime(serverType, getClass().getName() + serverType);
IServerWorkingCopy wc = server.createWorkingCopy();
ServerProfileModel.setProfile(wc, mode);
server = wc.save(false, new NullProgressMonitor());
}

@After
public void tearDown() throws Exception {
ServerCreationTestUtils.deleteAllServersAndRuntimes();
}


@Test
public void testResolution() throws Exception {
IControllableServerBehavior beh = JBossServerBehaviorUtils.getControllableBehavior(server);
assertNotNull(beh);
try {
ISubsystemController controller = beh.getController(IDeploymentOptionsController.SYSTEM_ID);
if( mode != null ) {
assertFalse(mode.contains(".mgmt"));
}
assertNotNull(controller);
} catch(CoreException ce) {
// management should fail to find this
assertTrue(mode.contains(".mgmt"));
}
}
}
Expand Up @@ -26,6 +26,8 @@
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
import org.eclipse.wst.server.core.model.ModuleDelegate;
import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.server.internal.ExtendedServerPropertiesAdapterFactory;
import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.ServerExtendedProperties;
import org.jboss.ide.eclipse.as.core.server.internal.v7.DeploymentMarkerUtils;
import org.jboss.ide.eclipse.as.core.util.ModuleResourceUtil;
import org.jboss.tools.as.core.server.controllable.subsystems.internal.StandardFileSystemPublishController;
Expand Down Expand Up @@ -157,9 +159,15 @@ public void testUtilInWebMockModule() throws Exception {

String utilDepDir = controller.getDeployPathController().getDeployDirectory(module).toOSString();
if( !testIsZip()) {
// we're not testing in zip mode, so utilDepDir should exist and should be a forced zip file
ServerExtendedProperties props = ExtendedServerPropertiesAdapterFactory.getServerExtendedProperties(server);
assertNotNull(props);
boolean allowExplodedUtil = props.allowExplodedModulesInWarLibs();

// we're not testing in zip mode, so utilDepDir should exist
assertTrue(new Path(utilDepDir).toFile().exists());
assertTrue(new Path(utilDepDir).toFile().isFile());

// and should be a forced zip file only if we're not allowing exploded utility jars
assertEquals(!allowExplodedUtil, new Path(utilDepDir).toFile().isFile());
verifyListRelativePath(new Path(utilDepDir), Arrays.asList(new IPath[]{new Path("Main.class")}), true);
} else {
// Our util is inside a zipped war. Verify that exists
Expand Down Expand Up @@ -280,10 +288,15 @@ private void utilInWebInEarRemovals_verifyWeb(String webDepDir, String earDepDir
}

private void utilInWebInEarRemovals_verifyUtil(String utilDepDir, String earDepDir, boolean shouldExist) {
ServerExtendedProperties props = ExtendedServerPropertiesAdapterFactory.getServerExtendedProperties(server);
assertNotNull(props);
boolean allowExplodedUtil = props.allowExplodedModulesInWarLibs();
if( !testIsZip()) {
// we're not testing in zip mode, so utilDepDir should exist and should be a forced zip file
// we're not testing in zip mode, so utilDepDir should exist
assertEquals(shouldExist, new Path(utilDepDir).toFile().exists());
assertEquals(shouldExist, new Path(utilDepDir).toFile().isFile());
// and should be a forced zip file only if we don't allow exploded util jars
boolean shouldBeFile = !allowExplodedUtil && shouldExist;
assertEquals(shouldBeFile, new Path(utilDepDir).toFile().isFile());
verifyListRelativePath(new Path(utilDepDir), Arrays.asList(new IPath[]{new Path("Main.class")}), shouldExist);
} else {
// Our util is inside a zipped war inside a zipped ear. Verify that exists
Expand Down
Expand Up @@ -17,6 +17,7 @@
@RunWith(Suite.class)
@SuiteClasses({
AllSubsystemResolutionTest.class,
DeploymentOptionsSubsystemResolutionTest.class,
BrowseBehaviorSubsystemResolutionTest.class,
ExploreBehaviorSubsystemResolutionTest.class,
PublishSubsystemResolutionTest.class,
Expand Down
@@ -0,0 +1,119 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.as.test.core.utiltests;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.*;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.util.RemotePath;
import org.jboss.ide.eclipse.as.core.util.ServerHomeValidationUtility;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IFilesystemController;
import org.jboss.ide.eclipse.as.wtp.core.server.behavior.IServerDetailsController;
import org.jboss.tools.as.core.server.controllable.systems.IDeploymentOptionsController;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

import junit.framework.TestCase;

/**
* This test just makes sure the server hoem validation
* will only request filesystem and serverdetails subsystems,
* and will not request deploymentoptions as some profiles don't have it.
*
*/
public class ServerHomeValidationUtilityTest extends TestCase {


@Test
public void testMockServerHomeValidator() throws CoreException {
IStatus ret = internalValidation("/home/user/test", "/", true);
assertTrue(ret.isOK());
}

@Test
public void testMockServerNullHome() throws CoreException {
IStatus ret = internalValidation(null, "/", true);
assertTrue(ret.getSeverity() == IStatus.ERROR);
}

@Test
public void testMockServerNullSep() throws CoreException {
IStatus ret = internalValidation("/home/user/test", null, true);
assertTrue(ret.getSeverity() == IStatus.ERROR);
}

@Test
public void testMockServerDNE() throws CoreException {
IStatus ret = internalValidation("/home/user/test", "/", false);
assertTrue(ret.getSeverity() == IStatus.ERROR);
}

@Test
public void testMockServerDeploymentOptions() throws CoreException {
try {
IStatus ret = internalValidation("/home/user/test", "/", true, true);
fail(); // should not reach
} catch(CoreException ce) {
// ignore
}
}

private IStatus internalValidation(String home, String sep, boolean exists) throws CoreException {
return internalValidation(home, sep, exists, false);
}

private IStatus internalValidation(String home, String sep, boolean exists, boolean loadDeploymentOptions) throws CoreException {

IServer s = mock(IServer.class);
ControllableServerBehavior delegate = mock(ControllableServerBehavior.class);
when(s.loadAdapter(ServerBehaviourDelegate.class, null)).thenReturn(delegate);
when(s.getAdapter(ServerBehaviourDelegate.class)).thenReturn(delegate);

IFilesystemController fs = mock(IFilesystemController.class);
IServerDetailsController details = mock(IServerDetailsController.class);

when(delegate.getController(IFilesystemController.SYSTEM_ID)).thenReturn(fs);
when(delegate.getController(IServerDetailsController.SYSTEM_ID)).thenReturn(details);
when(delegate.getController(IDeploymentOptionsController.SYSTEM_ID)).thenThrow(
new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, "Fail test")));


when(details.getProperty(IServerDetailsController.PROP_SERVER_HOME)).thenReturn(home);
when(details.getProperty(IServerDetailsController.SEPARATOR_CHAR)).thenReturn(sep);


IPath remoteHome = null;
if( sep != null && home != null )
remoteHome = new RemotePath(home, sep);

when(fs.exists(any(RemotePath.class),
any(IProgressMonitor.class))).thenReturn(exists);

if( loadDeploymentOptions ) {
delegate.getController(IDeploymentOptionsController.SYSTEM_ID);
}


IStatus ret = new ServerHomeValidationUtility().validateServerHome(s, false);
return ret;
}
}
Expand Up @@ -21,7 +21,8 @@
ExpressionResolverUtilTest.class,
UnitedServerListenerTest.class,
RSEUtilsTest.class,
VersionStringUtilTest.class
VersionStringUtilTest.class,
ServerHomeValidationUtilityTest.class
})
public class UtilsSuite {
}