Skip to content

Commit

Permalink
enhancement: update ProjectBuildFailure handling and cancel further b…
Browse files Browse the repository at this point in the history
…uild if failed
  • Loading branch information
SyntaxGalaxy committed Dec 16, 2024
1 parent 0c723a1 commit ac7c1cb
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ public void onBuildCancelled() {
}

@Override
public void onBuildFailed(ProjectCodeBuildException e) {
public void onBuildFailed(ProjectCodeBuildException e, long buildTime) {
log.append(e.getMessage());
log.append("\n");
activity.runOnUiThread(
() -> {
log.append("\n");
log.append("Build failed in ".concat(TimeUtils.convertTime(buildTime)));
log.append("\n");
binding.indicator.setVisibility(View.GONE);
binding.currentLog.setVisibility(View.GONE);
binding.editor.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.icst.android.appstudio.builder.JavaSourceBuilder;
import com.icst.android.appstudio.builder.LayoutSourceBuilder;
import com.icst.android.appstudio.exception.ProjectCodeBuildException;
import com.icst.android.appstudio.listener.BuildFailListener;
import com.icst.android.appstudio.listener.ProjectCodeBuildListener;
import com.icst.android.appstudio.models.ModuleModel;
import com.icst.android.appstudio.utils.EnvironmentUtils;
Expand Down Expand Up @@ -115,6 +116,8 @@ public static void generateModuleCode(
ProjectCodeBuildListener listener,
ProjectCodeBuilderCancelToken cancelToken) {

BuildFailListener buildFailListener = new BuildFailListener();

long executionStartTime = System.currentTimeMillis();
if (listener != null)
listener.onBuildStart();
Expand Down Expand Up @@ -272,7 +275,10 @@ public void onArtifactNotFound(Artifact artifact) {
.concat(artifact.getGroupId())
.concat(":")
.concat(artifact.getVersion()));
listener.onBuildFailed(artifactNotFound);
buildFailListener.notifyBuildFailed();
listener.onBuildFailed(
artifactNotFound,
System.currentTimeMillis() - executionStartTime);
}
}

Expand All @@ -287,7 +293,9 @@ public void onDependenciesNotFound(Artifact artifact) {
.concat(artifact.getGroupId())
.concat(":")
.concat(artifact.getVersion())));
listener.onBuildFailed(dependecyNotFound);
buildFailListener.notifyBuildFailed();
listener.onBuildFailed(
dependecyNotFound, System.currentTimeMillis() - executionStartTime);
}

@Override
Expand Down Expand Up @@ -315,7 +323,10 @@ public void onDownloadError(Artifact artifact, Throwable error) {
.concat(artifact.getGroupId())
.concat(":")
.concat(artifact.getVersion()));
listener.onBuildFailed(artifactNotFound);
buildFailListener.notifyBuildFailed();
listener.onBuildFailed(
artifactNotFound,
System.currentTimeMillis() - executionStartTime);
}
}

Expand Down Expand Up @@ -368,14 +379,18 @@ public void onInvalidPOM(Artifact artifact) {
.concat(artifact.getGroupId())
.concat(":")
.concat(artifact.getVersion()));
listener.onBuildFailed(invalidPOM);
buildFailListener.notifyBuildFailed();
listener.onBuildFailed(
invalidPOM, System.currentTimeMillis() - executionStartTime);
}

@Override
public void onInvalidScope(Artifact artifact, String scope) {
ProjectCodeBuildException invalidScope = new ProjectCodeBuildException();
invalidScope.setMessage("Invalid Scope : ".concat(scope));
listener.onBuildFailed(invalidScope);
buildFailListener.notifyBuildFailed();
listener.onBuildFailed(
invalidScope, System.currentTimeMillis() - executionStartTime);
}

@Override
Expand Down Expand Up @@ -419,7 +434,10 @@ public void onVersionNotFound(Artifact artifact) {
.concat(artifact.getGroupId())
.concat(":")
.concat(artifact.getVersion()));
listener.onBuildFailed(artifactNotFound);
buildFailListener.notifyBuildFailed();
listener.onBuildFailed(
artifactNotFound,
System.currentTimeMillis() - executionStartTime);
}
}
};
Expand Down Expand Up @@ -472,6 +490,10 @@ public void onVersionNotFound(Artifact artifact) {
}
}

if (buildFailListener.isFailed()) {
return;
}

AppBuilder apkBuilder = new AppBuilder();
apkBuilder.build(
new BuildListener() {
Expand All @@ -488,10 +510,18 @@ public void onBuildProgress(String arg) {
},
module);

if (buildFailListener.isFailed()) {
return;
}

long endExectionTime = System.currentTimeMillis();
long executionTime = endExectionTime - executionStartTime;
if (listener != null) {
listener.onBuildComplete(executionTime);
if (buildFailListener.isFailed()) {
listener.onBuildComplete(executionTime);
} else {
listener.onBuildComplete(executionTime);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of Android AppStudio [https://github.com/Innovative-CST/AndroidAppStudio].
*
* License Agreement
* This software is licensed under the terms and conditions outlined below. By accessing, copying, modifying, or using this software in any way, you agree to abide by these terms.
*
* 1. ** Copy and Modification Restrictions **
* - You are not permitted to copy or modify the source code of this software without the permission of the owner, which may be granted publicly on GitHub Discussions or on Discord.
* - If permission is granted by the owner, you may copy the software under the terms specified in this license agreement.
* - You are not allowed to permit others to copy the source code that you were allowed to copy by the owner.
* - Modified or copied code must not be further copied.
* 2. ** Contributor Attribution **
* - You must attribute the contributors by creating a visible list within the application, showing who originally wrote the source code.
* - If you copy or modify this software under owner permission, you must provide links to the profiles of all contributors who contributed to this software.
* 3. ** Modification Documentation **
* - All modifications made to the software must be documented and listed.
* - the owner may incorporate the modifications made by you to enhance this software.
* 4. ** Consistent Licensing **
* - All copied or modified files must contain the same license text at the top of the files.
* 5. ** Permission Reversal **
* - If you are granted permission by the owner to copy this software, it can be revoked by the owner at any time. You will be notified at least one week in advance of any such reversal.
* - In case of Permission Reversal, if you fail to acknowledge the notification sent by us, it will not be our responsibility.
* 6. ** License Updates **
* - The license may be updated at any time. Users are required to accept and comply with any changes to the license.
* - In such circumstances, you will be given 7 days to ensure that your software complies with the updated license.
* - We will not notify you about license changes; you need to monitor the GitHub repository yourself (You can enable notifications or watch the repository to stay informed about such changes).
* By using this software, you acknowledge and agree to the terms and conditions outlined in this license agreement. If you do not agree with these terms, you are not permitted to use, copy, modify, or distribute this software.
*
* Copyright © 2024 Dev Kumar
*/

package com.icst.android.appstudio.listener;

public final class BuildFailListener {
boolean isFailed = false;

public void notifyBuildFailed() {
isFailed = true;
}

public boolean isFailed() {
return this.isFailed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ public interface ProjectCodeBuildListener {

void onBuildCancelled();

void onBuildFailed(ProjectCodeBuildException e);
void onBuildFailed(ProjectCodeBuildException e, long buildTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ private static BlockModel getNumberEqualBlock() {
tag.setSupportedFileExtensions(new String[] { "java" });

DependencyTag testDeps = new DependencyTag();
testDeps.setDependencyGroup("group");
testDeps.setDependencyName("name");
testDeps.setVersion("version");
testDeps.setDependencyGroup("com.blankj");
testDeps.setDependencyName("utilcodex");
testDeps.setVersion("1.31.1");

tag.setAdditionalTags(new AdditionalCodeHelperTag[] { testDeps });
block.setTags(tag);
Expand Down

0 comments on commit ac7c1cb

Please sign in to comment.