Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Oomph » Unexpected Variable Filter behaviour(Variable Filter Behaviour)
Unexpected Variable Filter behaviour [message #1823350] Wed, 25 March 2020 11:02 Go to next message
Keith Ralphs is currently offline Keith RalphsFriend
Messages: 4
Registered: March 2020
Junior Member
Hi,

I'm trying to use the basePath and lastSegment Variable filters to select between alternate values in a String variable. I have a variable task called gdabranchindex with choices which produces a value of the form "valA/valB" or "0". I then define two new variableTasks based on this using the filters as below:

  <setupTask
      xsi:type="setup:VariableTask"
      excludedTriggers="STARTUP MANUAL"
      id="dls.dawnbranch"
      name="dawnbranch"
      value="dawn-2.${gdabranchindex|lastSegment}"
      filter="(!(gdabranchindex=0))">
  </setupTask>
  <setupTask
      xsi:type="setup:VariableTask"
      excludedTriggers="STARTUP MANUAL"
      id="dls.gdabranch"
      name="gdabranch"
      value="gda-9.${gdabranchindex|basePath}"
      filter="(!(gdabranchindex=0))">
  </setupTask>


from this I was expecting to get the values of dawnBranch to be dawn-2.valB and gdaBranch to be gda-9.valA. What I actually get id dawnBranch has the value dawn2-valA and gda branch has the value gda-9..

I looked at the latest code for String FilterRegistry and it looks like it should do what I expect, so I then copied the appropriate methods into a test class that I ran on a Java repl , here it is:

class Main {
  public static void main(String[] args){
    String it = "16/17";
    System.out.println(filterBase(it));
    System.out.println(filterLast(it));
  }

  public static String filterBase(String value) {
    value = value.replaceAll("\\\\", "/");
    int pos = value.lastIndexOf('/');
    if (pos == -1){
      return "Nuttin";
    }
    return value.substring(0, pos);
  }
  public static String filterLast(String value) {
    int pos = Math.max(value.lastIndexOf('/'), value.lastIndexOf('\\'));
    if (pos == -1) {
      return value;
    }
    return value.substring(pos + 1);
  }
}


When I run this is does behave as expected producing the output:
16
17


Do you have any ideas as to what is going on here as the filters I'm selecting seem like the right ones but I'm not getting the expected output?
Re: Unexpected Variable Filter behaviour [message #1823476 is a reply to message #1823350] Fri, 27 March 2020 06:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
I'm trying to wrap my head around how you would use these two different variables. Putting a filter on a variable effectively will exclude it from being defined at all when the filter doesn't match. So how/where are these variables ultimately used? The task that uses them must also be filtered with the same filter so that the task also isn't needed (so that the variables isn't really used). From your initial description it sounded more like you wanted a single variable whose value is different depending on some filter (some other variable's value), but instead you've defined two variables both of which will effectively have an undefined value (the variable will not even be defined) when the filter doesn't match. So I'm missing the conceptual context.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Unexpected Variable Filter behaviour [message #1823487 is a reply to message #1823476] Fri, 27 March 2020 09:21 Go to previous messageGo to next message
Keith Ralphs is currently offline Keith RalphsFriend
Messages: 4
Registered: March 2020
Junior Member
Hi Ed,

I have two other variable setupTasks (which I left out for simplicity) that provide the values for dawnbranch and gdabranch when gdabranchindex = 0 so (my understanding is that) these two variables should always be defined, hence other tasks can use them without filtering. As you said, what I'm really trying to do is make one variable selection ( the current gda branch minor number) to produce two related values:

For historical reasons, the two products we produce have minor version numbers which are always 1 apart - the dawn version being the gda version + 1. When we materialize the gda workspace we use some dawn components and thus, if materilizing a specific release branch, need to get gda 9.x components and dawn 2.x+1 components.

I tried to achieve this by making the gdabranchindex an INTEGER variable, but there doesn't seem to be a way to then add 1 to it when required within the oomph syntax. After this, variable filters seemed like they might be an option and as the basePath and lastElement ones are really just string splitters based around the final ocurrence of '/', my hope was I would be able to pass in a string of the form "16/17" and get "16" out from the former and "17" from the latter. However, as I say this wasn't the result.

Instead, when I set the value of gdabranchindex to be "16/17" (meaning the setupTask filter will be satisfied for both the dls.gdabranch and dls.dawnbranch tasks) the value of these variables after applying their variable filters are "" and "16" respectively which I don't understand, can you explain why?

Obviously if there is a less convoluted way of getting (from the selection of one variable) one variable with the value x and another with the value x+1 I'd be very intereseted in that too.

thanks,

Keith
Re: Unexpected Variable Filter behaviour [message #1823490 is a reply to message #1823487] Fri, 27 March 2020 09:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
I try replicate what you do. So I create this in my Workspace.setup using Navigate -> Open Setup -> Workspace:
<?xml version="1.0" encoding="UTF-8"?>
<setup:CompoundTask
    xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:setup="http://www.eclipse.org/oomph/setup/1.0">
  <setupTask
      xsi:type="setup:VariableTask"
      type="BOOLEAN"
      name="filter"
      label="Filter"/>
  <setupTask
      xsi:type="setup:VariableTask"
      name="path"
      value="a-true/b-false"/>
  <setupTask
      xsi:type="setup:VariableTask"
      filter="(filter=true)"
      name="sample"
      value="Value When Filter True ${path|basePath}"/>
  <setupTask
      xsi:type="setup:VariableTask"
      filter="(filter=false)"
      name="sample"
      value="Value When Filter False ${path|lastSegment}"/>
  <setupTask
      xsi:type="setup:StringSubstitutionTask"
      name="string_substitution"
      value="${sample}"/>
  <description>Test</description>
</setup:CompoundTask>
Then I do Perform Setup Tasks and I'm prompted for Filter. Then I go to the next page and can look at the String Substitution task. When it's not checked, I see
<?xml version="1.0" encoding="UTF-8"?>
<setup:StringSubstitutionTask
    xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI"
    xmlns:setup="http://www.eclipse.org/oomph/setup/1.0"
    name="string_substitution"
    value="Value When Filter False b-false"/>
When it's checked, I see:
<?xml version="1.0" encoding="UTF-8"?>
<setup:StringSubstitutionTask
    xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI"
    xmlns:setup="http://www.eclipse.org/oomph/setup/1.0"
    name="string_substitution"
    value="Value When Filter True a-true"/>
So from this I conclude that it works properly.

If you have something that doesn't work, I need to see all the context. So ideally you boil it down to an example that you can copy and paste into the forum. (If you use Copy from the context menu and paste that, I can copy it from the forum and paste into in any setup editor to test it.)


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Filter on Java version >= 11
Next Topic:Simple "Find and Replace" TextModification
Goto Forum:
  


Current Time: Sat May 04 20:12:10 GMT 2024

Powered by FUDForum. Page generated in 0.03127 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top