Skip to content

Commit

Permalink
added script root paths provider
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Feb 26, 2023
1 parent 12a875f commit c366055
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.cognifide.apm.api.scripts.LaunchEnvironment;
import com.cognifide.apm.api.scripts.LaunchMode;
import com.cognifide.apm.api.scripts.MutableScript;
import com.cognifide.apm.api.services.ExecutionMode;
import com.cognifide.apm.api.services.ScriptManager;
import com.cognifide.apm.core.Apm;
import com.cognifide.apm.core.utils.PathUtils;
import com.cognifide.apm.core.utils.ResourceMixinUtil;
Expand All @@ -35,15 +37,18 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import javax.jcr.RepositoryException;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -58,6 +63,10 @@ public class ScriptModel implements MutableScript {
@Self
private Resource resource;

@Inject
@OSGiService
private ScriptManager scriptManager;

@Inject
@Named(ScriptNode.APM_LAUNCH_ENABLED)
private Boolean launchEnabled;
Expand Down Expand Up @@ -108,6 +117,17 @@ public ScriptModel(Resource resource) {
this.path = resource.getPath();
}

@PostConstruct
private void afterCreated() {
if (verified == null) {
try {
scriptManager.process(this, ExecutionMode.VALIDATION, resource.getResourceResolver());
} catch (RepositoryException | PersistenceException e) {
LOGGER.error("", e);
}
}
}

@Override
public boolean isValid() {
return BooleanUtils.toBoolean(verified);
Expand Down

0 comments on commit c366055

Please sign in to comment.