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-24184] get debug port and devmode switch from image #1518

Merged
merged 1 commit into from
Aug 10, 2017
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 @@ -60,5 +60,5 @@ public static <T> T getFirstElement(Collection<T> collection) {
}

return collection.iterator().next();
}
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015 Red Hat, Inc.
* Copyright (c) 2017 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 @@ -11,7 +11,6 @@
package org.jboss.tools.openshift.internal.common.ui.databinding;

import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.MultiValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;

Expand All @@ -20,25 +19,25 @@
*
* @author Andre Dietisheim
*/
public class RequiredStringValidationProvider extends MultiValidator {
public class DisablableRequiredStringMultiValidator extends RequiredStringMultiValidator {

private IObservableValue observableValue;
private String name;
private IObservableValue<Boolean> disabledObservable;

public RequiredStringValidationProvider(IObservableValue value, String name) {
this.observableValue = value;
observableValue.getValue();
this.name = name;
public DisablableRequiredStringMultiValidator(IObservableValue<String> value, IObservableValue<Boolean> disabledObservable, String errorMessage) {
super(errorMessage, value);
this.disabledObservable = disabledObservable;
}

@Override
protected IStatus validate() {
Object value = observableValue.getValue();
if (!(value instanceof String)
|| ((String) value).isEmpty()) {
return ValidationStatus.cancel("You have to provide a " + name);
if (!isDisabled()) {
return super.validate();
}
return ValidationStatus.ok();
}

protected boolean isDisabled() {
Boolean disabled = this.disabledObservable.getValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

return this.disabledObservable.getValue(); is enough 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.

i dont think so, since it could be null

return Boolean.TRUE.equals(disabled);
}
}
@@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright (c) 2015-2017 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.openshift.internal.common.ui.databinding;

import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.MultiValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.jboss.tools.openshift.common.core.utils.StringUtils;

/**
* A validator whose state may be observed.
*
* @author Andre Dietisheim
*/
public class RequiredStringMultiValidator extends MultiValidator {

private IObservableValue<String> observableValue;
private String name;
private String errorMessage;

public RequiredStringMultiValidator(IObservableValue<String> value, String name) {
this(value, name, null);
}

public RequiredStringMultiValidator(String errorMessage, IObservableValue<String> value) {
this(value, null, errorMessage);
}

protected RequiredStringMultiValidator(IObservableValue<String> value, String name, String errorMessage) {
this.observableValue = value;
this.name = name;
this.errorMessage = errorMessage;
}

@Override
protected IStatus validate() {
String value = observableValue.getValue();
if (!isValueProvided(value)) {
return ValidationStatus.cancel(getErrorMessage());
}
return validateValue(value);
}

protected boolean isValueProvided(String value) {
return !StringUtils.isEmpty(value);
}

protected IStatus validateValue(String value) {

Choose a reason for hiding this comment

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

MAJOR Remove this unused method parameter "value". rule

return ValidationStatus.ok();
}

protected String getErrorMessage() {
if (errorMessage != null) {
return errorMessage;
} else {
return "Please provide a value for " + name;
}
}

}
21 changes: 10 additions & 11 deletions plugins/org.jboss.tools.openshift.core/META-INF/MANIFEST.MF
Expand Up @@ -32,7 +32,9 @@ Require-Bundle: org.jboss.tools.openshift.client;bundle-version="[3.0.0,4.0.0)",
com.fasterxml.jackson.core.jackson-databind;bundle-version="2.5.0",
com.fasterxml.jackson.core.jackson-core;bundle-version="2.5.0",
org.jboss.tools.jmx.jolokia;bundle-version="1.8.2",
org.jboss.ide.eclipse.as.jmx.integration
org.jboss.ide.eclipse.as.jmx.integration,
org.eclipse.linuxtools.docker.core,
org.apache.commons.collections
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.openshift.core,
Expand All @@ -43,15 +45,12 @@ Export-Package: org.jboss.tools.openshift.core,
org.jboss.tools.openshift.core.server.behavior,
org.jboss.tools.openshift.core.server.behavior.eap,
org.jboss.tools.openshift.core.util,
org.jboss.tools.openshift.internal.core;x-friends:="org.jboss.tools.openshift.test,org.jboss.tools.openshift.ui,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.models;x-friends:="org.jboss.tools.openshift.test,org.jboss.tools.openshift.ui,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.portforwarding;x-friends:="org.jboss.tools.openshift.test,org.jboss.tools.openshift.ui,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.preferences;x-friends:="org.jboss.tools.openshift.test,org.jboss.tools.openshift.ui,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.server.debug;
x-friends:="org.jboss.tools.openshift.test,
org.jboss.tools.openshift.ui,
org.jboss.tools.openshift.reddeer,
org.jboss.tools.openshift.js",
org.jboss.tools.openshift.internal.core.util;x-friends:="org.jboss.tools.openshift.test,org.jboss.tools.openshift.ui,org.jboss.tools.openshift.reddeer"
org.jboss.tools.openshift.internal.core;x-friends:="org.jboss.tools.openshift.ui,org.jboss.tools.openshift.js,org.jboss.tools.openshift.test,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.docker;x-friends:="org.jboss.tools.openshift.ui,org.jboss.tools.openshift.js,org.jboss.tools.openshift.test,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.models;x-friends:="org.jboss.tools.openshift.ui,org.jboss.tools.openshift.js,org.jboss.tools.openshift.test,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.portforwarding;x-friends:="org.jboss.tools.openshift.ui,org.jboss.tools.openshift.js,org.jboss.tools.openshift.test,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.preferences;x-friends:="org.jboss.tools.openshift.ui,org.jboss.tools.openshift.js,org.jboss.tools.openshift.test,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.server.debug;x-friends:="org.jboss.tools.openshift.ui,org.jboss.tools.openshift.js,org.jboss.tools.openshift.test,org.jboss.tools.openshift.reddeer",
org.jboss.tools.openshift.internal.core.util;x-friends:="org.jboss.tools.openshift.ui,org.jboss.tools.openshift.js,org.jboss.tools.openshift.test,org.jboss.tools.openshift.reddeer"
Service-Component: META-INF/connectionFactory.xml

Expand Up @@ -27,6 +27,8 @@ public interface OpenShiftAPIAnnotations {
static final String DEPLOYMENT_CONFIG_NAME = "openshift.io/deployment-config.name";
static final String DEPLOYMENT_NAME = "openshift.io/deployment.name";

static final String DEPLOYER_POD_FOR = "openshift.io/deployer-pod-for.name";

static final String GENERATED_BY = "openshift.io/generated-by";

static final String DESCRIPTION = "description";
Expand Down
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2017 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.openshift.core;

/**
* The list of well known selectors that can be consumed by the tooling
*
* @author Andre Dietisheim
*/
public interface OpenShiftResourceSelectors {

Choose a reason for hiding this comment

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

CRITICAL Move constants to a class or enum. rule

/** as in eap templates **/
static final String DEPLOYMENT_CONFIG = "deploymentconfig";
}
@@ -0,0 +1,89 @@
/*******************************************************************************
* Copyright (c) 2016-2017 Red Hat Inc..
* All rights reserved. This program and the accompanying materials
* are 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 Incorporated - initial API and implementation
*******************************************************************************/
package org.jboss.tools.openshift.core.server;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jboss.tools.openshift.common.core.utils.StringUtils;

/**
* @author Andre Dietisheim
*/
public class DevmodeMetadata {

// default fallback
private static final String DEFAULT_ENABLEMENT_KEY = "DEBUG";
private static final String DEFAULT_ENABLEMENT_VALUE = "true";
private static final String DEFAULT_PORT_KEY = "DEBUG_PORT";
private static final String DEFAULT_PORT_VALUE = "8787";

// "image->"dockerImageMetadata"->"Config"->"Labels"->
private static final Pattern REGEX_LABEL_DEVMODE = Pattern
.compile("\\\"com\\.redhat\\.dev-mode\\\" ?\\: ?\\\"([^(:|\\\")]+)(:|\\\")([^\\\"]*)");
private static final Pattern REGEX_LABEL_DEVMODE_PORT = Pattern
.compile("\\\"com\\.redhat\\.dev-mode\\.port\\\" ?\\: ?\\\"([^(:|\\\")]+)(:|\\\")([^\\\"]*)");

private String enablementKey;
private String enablementValue;
private String portKey;
private String portValue;

public DevmodeMetadata(String metadata) {
parse(metadata);
}

public String getEnablementKey() {
return enablementKey;
}

public String getEnablementValue() {
return enablementValue;
}

public String getPortKey() {
return portKey;
}

public String getPortValue() {
return portValue;
}

private void parse(String metadata) {
if (!StringUtils.isEmpty(metadata)) {
parseEnablement(metadata);
parsePort(metadata);
}
}

private void parseEnablement(String metadata) {
Matcher matcher = REGEX_LABEL_DEVMODE.matcher(metadata);
if (matcher.find()) {
this.enablementKey = matcher.group(1);
this.enablementValue = matcher.group(3);
} else {
this.enablementKey = DEFAULT_ENABLEMENT_KEY;
this.enablementValue = DEFAULT_ENABLEMENT_VALUE;
}
}

private void parsePort(String metadata) {
Matcher matcher = REGEX_LABEL_DEVMODE_PORT.matcher(metadata);
if (matcher.find()) {
this.portKey = matcher.group(1);
this.portValue = matcher.group(3);
} else {
this.portKey = DEFAULT_PORT_KEY;
this.portValue = DEFAULT_PORT_VALUE;
}
}

}