Skip to content

Commit

Permalink
Merge pull request #50 from paypal/develop
Browse files Browse the repository at this point in the history
Changes for version 2.1.0
  • Loading branch information
fabiocarvalho777 authored Dec 2, 2017
2 parents c597ba5 + 1a5a1f0 commit 52cb6c4
Show file tree
Hide file tree
Showing 337 changed files with 86,738 additions and 61 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ metrics/

# Package Files #
*.jar
*.war
*.ear

# IDE Files #
.classpath
Expand Down
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ sudo: required
jdk:
- oraclejdk8

branches:
only:
- develop

install: mvn install

after_success:
Expand All @@ -18,5 +22,5 @@ after_success:
- java -cp ccr.jar com.codacy.CodacyCoverageReporter -l Java -r ./butterfly-metrics-couchdb/target/site/cobertura/coverage.xml --projectToken $CODACY_PROJECT_TOKEN
- java -cp ccr.jar com.codacy.CodacyCoverageReporter -l Java -r ./butterfly-metrics-file/target/site/cobertura/coverage.xml --projectToken $CODACY_PROJECT_TOKEN
- java -cp ccr.jar com.codacy.CodacyCoverageReporter -l Java -r ./butterfly-utilities/target/site/cobertura/coverage.xml --projectToken $CODACY_PROJECT_TOKEN
# Deploying SNAPSHOT artifacts to Maven Central
- mvn -B -s settings.xml -DskipTests=true -Dcobertura.skip deploy
# Deploying artifacts to Maven Central
- mvn -B -s settings.xml -DskipTests=true -Dcobertura.skip deploy -Possrh
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.paypal.butterfly/butterfly-parent/badge.svg?style=flat)](http://search.maven.org/#search|ga|1|g:com.paypal.butterfly)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# Butterfly
<br><br>
<div style="text-align:center"><img src ="docs/img/logo/butterfly.png" /></div>
<br>

Butterfly is an application code transformation tool, and commonly it is used to perform **automated application migrations**, **upgrades** and **source code and configuration changes**.

Expand Down
2 changes: 1 addition & 1 deletion butterfly-cli-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.paypal.butterfly</groupId>
<artifactId>butterfly-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion butterfly-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.paypal.butterfly</groupId>
<artifactId>butterfly-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ public ButterflyCliRun run() throws IOException {

run.setTransformationTemplate(templateClass.getName());

logger.info("Application to be transformed: {}", applicationFolder);
logger.info("Transformation template class: {}", templateClass.getName());
TransformationResult transformationResult = null;
if (UpgradeStep.class.isAssignableFrom(templateClass)) {
Class<? extends UpgradeStep> firstStepClass = (Class<? extends UpgradeStep>) templateClass;
Expand Down
2 changes: 1 addition & 1 deletion butterfly-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.paypal.butterfly</groupId>
<artifactId>butterfly-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ public TransformationTemplate getTemplate() {
return template;
}

@Override
String getExtensionName() {
return getExtensionName(template.getExtensionClass());
}

@Override
String getExtensionVersion() {
return getExtensionVersion(template.getExtensionClass());
}

@Override
String getTemplatetName() {
return template.getName();
}

@Override
public String toString() {
return String.format(TO_STRING_SYNTAX, getApplication(), template, template.getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.paypal.butterfly.core;

import com.paypal.butterfly.extensions.api.Extension;
import com.paypal.butterfly.facade.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

Expand All @@ -12,6 +15,8 @@
*/
public abstract class Transformation {

private static final Logger logger = LoggerFactory.getLogger(Transformation.class);

// Application to be transformed
private Application application;

Expand Down Expand Up @@ -64,4 +69,24 @@ File getManualInstructionsDir() {
return manualInstructionsDir;
}

abstract String getExtensionName();

abstract String getExtensionVersion();

abstract String getTemplatetName();

protected String getExtensionName(Class<? extends Extension> extension) {
return extension.getName();
}

protected String getExtensionVersion(Class<? extends Extension> extension) {
String version = "UNKNOWN";
try {
version = extension.newInstance().getVersion();
} catch (Exception e) {
logger.warn("Error happened when retrieving extension version", e);
}
return version;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public TransformationResult perform(Transformation transformation) throws Transf
if(logger.isDebugEnabled()) {
logger.debug("Requested transformation: {}", transformation);
}
logger.info("Extension name:\t\t\t\t\t{}", transformation.getExtensionName());
logger.info("Extension version:\t\t\t\t{}", transformation.getExtensionVersion());
logger.info("Transformation template:\t\t\t{}", transformation.getTemplatetName());

File transformedAppFolder = prepareOutputFolder(transformation);
List<TransformationContextImpl> transformationContexts = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ public UpgradePath getUpgradePath() {
return upgradePath;
}

@Override
String getExtensionName() {
return getExtensionName(upgradePath.getExtension());
}

@Override
String getExtensionVersion() {
return getExtensionVersion(upgradePath.getExtension());
}

@Override
String getTemplatetName() {
return upgradePath.getFirstStepTemplateName();
}

@Override
public String toString() {
return String.format(TO_STRING_SYNTAX, getApplication(), upgradePath.getOriginalVersion(), upgradePath.getUpgradeVersion());
Expand Down
2 changes: 1 addition & 1 deletion butterfly-extensions-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.paypal.butterfly</groupId>
<artifactId>butterfly-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
* based on evaluating a single file see {@link SingleCondition}.
* For conditions based on multiple files see {@link MultipleConditions}
*
* IMPORTANT:
* Every DoubleUtilityCondition subclass MUST be a Java bean, which means they must have
* a public no arguments default constructor, and also public setters and getters for all
* their properties. In addition to that, every setter must return the
* DoubleUtilityCondition instance.
*
* @see SingleCondition
* @see MultipleConditions
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
/**
* Transformation utility condition to determine if a transformation utility should be executed or not,
* based on a multiple files criteria.
* It performs condition instances based on a template against multiple files,
* It performs condition instances based on a {@link SingleCondition} template against multiple files,
* returning true if at least one file meets the condition (default mode).
* There is an alternative mode where all files need to meet the
* evaluation condition to result in true. For conditions
* based on comparing two files see {@link DoubleCondition}.
* For conditions based on evaluating a single file see {@link MultipleConditions}
* For conditions based on evaluating a single file see {@link SingleCondition}
* <br>
* Note 1: if an evaluation against a specific file fails for any reason, then the
* overall evaluation will be interrupted and result also in a failure.
Expand Down Expand Up @@ -64,7 +64,7 @@ public enum Mode {

// The utility condition template used to create conditions
// to by evaluated against the list of files
private UtilityCondition conditionTemplate;
private SingleCondition conditionTemplate;

// This is used to set condition instances names
private int conditionInstanceCounter = 0;
Expand All @@ -80,7 +80,7 @@ public enum Mode {
* @param conditionTemplate the utility condition template used to create conditions,
* used to be evaluated against the list of files
*/
public MultipleConditions(UtilityCondition conditionTemplate) {
public MultipleConditions(SingleCondition conditionTemplate) {
setConditionTemplate(conditionTemplate);
}

Expand Down Expand Up @@ -123,7 +123,7 @@ public MultipleConditions setFiles(String... filesAttributes) {
* to be evaluated against the list of files
* @return this utility condition instance
*/
public MultipleConditions setConditionTemplate(UtilityCondition conditionTemplate) {
public MultipleConditions setConditionTemplate(SingleCondition conditionTemplate) {
checkForNull("conditionTemplate", conditionTemplate);
this.conditionTemplate = conditionTemplate;
return this;
Expand Down Expand Up @@ -160,7 +160,7 @@ public String[] getFilesAttributes() {
*
* @return the condition template
*/
public UtilityCondition getConditionTemplate() {
public SingleCondition getConditionTemplate() {
return conditionTemplate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
* based on comparing two files see {@link DoubleCondition}.
* For conditions based on multiple files see {@link MultipleConditions}
*
* IMPORTANT:
* Every SingleUtilityCondition subclass MUST be a Java bean, which means they must have
* a public no arguments default constructor, and also public setters and getters for all
* their properties. In addition to that, every setter must return the
* SingleUtilityCondition instance.
*
* @see DoubleCondition
* @see MultipleConditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,27 +599,29 @@ public PerformResult perform(File transformedAppFolder, TransformationContext tr
// Applying properties during transformation time
applyPropertiesFromContext(transformationContext);

TransformationUtilityException ex = null;

try {
ExecutionResult executionResult = execution(transformedAppFolder, transformationContext);
result = PerformResult.executionResult(this, executionResult);
} catch(Exception e) {
String exceptionMessage = String.format("Utility %s has failed", getName());
TransformationUtilityException ex = new TransformationUtilityException(exceptionMessage, e);
ex = new TransformationUtilityException(exceptionMessage, e);
return PerformResult.error(this, ex);
} finally {
// This if and the following below, even though similar, address different execution paths,
// so they must both be here, do not remove none of them thinking that this is redundant code
if (result == null) {
if (result == null && ex == null) {
String exceptionMessage = String.format("Utility %s has failed and has not produced any exception detailing the failure. This utility code might be defective, or you might be using a non supported JRE (such as Open JDK 1.7).", getName());
TransformationUtilityException ex = new TransformationUtilityException(exceptionMessage);
ex = new TransformationUtilityException(exceptionMessage);
logger.error("", ex);
}
hasBeenPerformed.set(true);
}

if (result == null) {
String exceptionMessage = String.format("Utility %s has failed and has not produced any exception detailing the failure. This utility code might be defective, since they must never return null.", getName());
TransformationUtilityException ex = new TransformationUtilityException(exceptionMessage);
ex = new TransformationUtilityException(exceptionMessage);
result = PerformResult.error(this, ex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,15 @@ public UpgradeStep next() {
return stepToReturn;
}

/**
* Return the name of the upgrade template to be performed
* as the first step in this upgrade path
*
* @return the name of the upgrade template to be performed
* as the first step in this upgrade path
*/
public String getFirstStepTemplateName() {
return firstStep.getClass().getName();
}

}
2 changes: 1 addition & 1 deletion butterfly-facade/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.paypal.butterfly</groupId>
<artifactId>butterfly-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion butterfly-metrics-couchdb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.paypal.butterfly</groupId>
<artifactId>butterfly-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion butterfly-metrics-file/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.paypal.butterfly</groupId>
<artifactId>butterfly-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion butterfly-utilities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.paypal.butterfly</groupId>
<artifactId>butterfly-parent</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<relativePath>..</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.paypal.butterfly.utilities.conditions;

import com.paypal.butterfly.extensions.api.ExecutionResult;
import com.paypal.butterfly.extensions.api.SingleCondition;
import com.paypal.butterfly.extensions.api.TUExecutionResult;
import com.paypal.butterfly.extensions.api.TransformationContext;
import com.paypal.butterfly.extensions.api.SingleCondition;
import com.paypal.butterfly.extensions.api.exception.TransformationUtilityException;

import java.io.File;
Expand All @@ -29,6 +28,10 @@ public class PropertyExists extends SingleCondition<PropertyExists> {
public PropertyExists() {
}

public PropertyExists(String propertyName) {
setPropertyName(propertyName);
}

public PropertyExists setPropertyName(String propertyName) {
checkForBlankString("propertyName", propertyName);
this.propertyName = propertyName;
Expand All @@ -55,7 +58,7 @@ public String getDescription() {
}

@Override
protected ExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
protected TUExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {

// TODO
// Move this to pre-validation method
Expand Down
Loading

0 comments on commit 52cb6c4

Please sign in to comment.